Build eclipse project with ant - eclipse

I am developing JSR 268 compliant portlet and utility with eclipse.
Now, the utility is designed to be a separate JAR from the portlet itself.
Does anyone now how to write an ant build.xml that will
1. Compile and JAR my utility class
2. Move the JAR to the ./lib folder of the portlet
3. Compile and maybe even delpoy the portlet to a tomcat running on localhost?
My biggest problem right now are the build-time dependencies. I dont want to hardcode all the folders as I share this project with two other developers which are on another platform.
Is it possible to reuse the buildpath from eclipse?
Thank you in advance,
Felipe

Does this wizard help
Rigth-click on project -> Export ... -> Ant buildfiles.
?

Though you probably have figured something out by now, for future references I would suggest taking a look at Eclipse's ability to use Ant files as project builders.
An advantage of this is, that will happen automatically as you build and since you only pack and copy the jar file, you don't have to worry about changes in e.g. the class paths, as you would in the two previous answers
Create a ant file that jar the utility project. Follow: [1]
Add it as a ant-builder to your utility project as described in [1]
Now Eclipse will automatically generate the jar file every time you build.
Extend the ant script to also copy to jar file to the lib dir.
Eclipse have ant task to convert workspace/project relative paths to
normal file paths. See [2]. Note that for those tasks to work, you must select ''Run is the same JRE as the workspace'' under the ''JRE'' tab when configuring the ant builder
In order to ensure your utility is build first add a project reference from your portlet to your utility project right click > properties > project references
When you build the following will now happen:
You utility project will build first, because of the project reference
The ant-builder will pack the jar, and copy it to the lib folder.
You portlet project will build using the new jar.
[1] http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2FgettingStarted%2Fqs-92_project_builders.htm
[2] http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/ant_eclipse_tasks.htm

For 1. Just use the and Ant tasks
For 2. Is it on a remote server? How do you get it there? Windows share?
For 3. Set up the Tomcat manager and then use Tomcat's deploy/undeploy Ant tasks:
http://blog.techstacks.com/2009/05/tomcat-management-setting-up-tomcat.html
<taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask" />
<taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask" />
If you want to avoid hard-coding paths, try to use relative paths. Where are you dependencies right now? What do you feel you may have to specify an absolute path for?

In Eclipse,
Goto Window->preference->Ant->Runtime->Classpath->ant Home
Then add what are the thing u need to add,atlast click ok button to create ant file.

Related

Exclude Ivy Dependencies in WAR File

I use Eclipse and the Ivy plugin IvyDE.
I currently create a WAR file by using Eclipse's export to WAR functionality. I don't use an ANT build file - I let Eclipse handle that.
When I export to war, all the dependencies in the ivy.xml file get copied to the war file's bin directory. I want to exclude one (or more) of them. How do I do that?
What't the simplest way to accomplish this? If possible, I would like to avoid creating my own ANT build files and continue to use Eclipse's export tool and the IvyDE plugin.
For me the following did the trick:
copy the ivy.xml to e.g. ivy-nodeploy.xml
create/select the configurations you want to include in the deployment assembly in ivy.xml
create/select the configurations you don't want to include in the deployment assembly in ivy-nodeploy.xml
add a new ivy-library to the build path where you change the default ivy-filename to
ivy-nodeploy.xml
That way you still have all ivy managed libraries at compile time in your build path but only libraries configured in ivy.xml get included in the war file.
Right click on your project's ivy.xml, and choose "Add ivy library".
In the main tab are customization settings for the build configs, and it looks as though you can choose the conf you desire (i.e. set it to runtime). I war using Ant, so I've never tried it. I presume this will accomplish what you desire.

Automatic Build for Non-Java Eclipse Project

I have a project that contains xml files. I also have an Ant build in that project to generate documentation based on the xml files. The Ant build calls a Ruby script for generation.
I would like a way run that Ant build after the modification of any resource in the "{project}/xml" folder. I know that I can right click on the build.xml and Run As->Ant Build, but I want it to be more like the incremental build for Java projects. I have tried creating a builder, importing the Ant build and setting up relevant resources, but when I make a change to the XML file, a build does not start. I have "Build Automatically" checked for the project as well.
This must be possible. What am I missing?
A custom builder will only run when a file is saved that is in a source directory. Make sure the /xml folder is included as a source location in the Project Properties, Java Build Path.

I need Eclipse to deploy the WAR file my ANT script builds, not what it builds internally

I'm using Eclipse Helios. I have a dynamic web project going and I've set up Eclipse to use an Ant Builder to generate a WAR file. This all works fine; if I change a .java file, Eclipse automatically runs my build.xml via Ant and updates my WAR. If I deploy the WAR to an external instance of Tomcat, it works perfectly.
However, when I tell Eclipse to run my project under Tomcat, it is not using the WAR file generated by the Ant build, or using my Ant script to generate a temporary WAR.
I know this because my build.xml script includes some additional XML configuration files in WEB-INF/classes in the WAR that are not ending up in the WEB-INF/classes dir that Eclipse pushes out.
I can't seem to find anything within Eclipse that says "when you publish, use this WAR file instead of building your own".
An alternate approach would be to tell Tomcat when it is building a WAR to do so by adding a list of files, but I can't seem to find a way to do that either.
I'm also curious how Eclipse knows what to publish since it is obviously ignoring my build.xml and my previously-generated WAR file.
Eclipse deploys a web application by looking at the Web Deployment Assembly options for your project. You can see this by right-clicking the project, choosing Properties, and then click on Deployment Assembly. Eclipse usually uses an expanded directory deployment here rather than creating and deploying a WAR (this is based on the server plugin being used, but I think most of them use an expanded directory structure for speed). If you export as a WAR it will create a WAR with the same content.
There are two main choices to do what you'd like:
Modify the Web Deployment Assembly options to match exactly what you would like in the deployed app
Don't use Eclipse's deployment; add an "External Ant Builder" to the "Builders" options for your project (right-click project, choose Properties->Builders). You can then select which targets in the ant file you want to use when eclipse builds the project. One of these options can be a deployment step
I can't seem to find anything within Eclipse that says "when you publish, use this WAR file instead of building your own".
I'm an IntelliJ user, so take this with a grain of salt. But...
Right-click on the Project Explorer target/foo.war, select Mark Deployable.
Then right-click on the foo.war file again and Run As... -> Run On Server...
Choose the JBoss instance.
If you go to the Servers view, you'll now see your WAR file under the JBoss instance as /proj_root/target/foo.war
Oh Eclipse, sigh...

NetBeans Library using JNI

Can I have a Library defined that makes use of JNI in NetBeans?
Seems the library definition only allows Jars or Folders.
How can I assure that the DLL follows the jar file when the app is built?
Assuming you are referring to building a NetBeans Platform App (or module), then you can place the DLL in the "release/modules/lib/" folder. This is per the platform FAQ:
http://wiki.netbeans.org/DevFaqNativeLibraries
Additional information here:
http://bits.netbeans.org/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/api.html#jni
If you are asking more generally, then I think most people package the DLL inside the jar, then extract it to a temp location upon application startup. e.g.
How to make a JAR file that includes DLL files?
If that's not what you're looking for, then you'll need to provide more information as to what you're trying to do.
netbeans won't do it on its own, but since it uses ant behind the scenes there's a workaround.
you should create a subdirectory named jni in your project directory (c:\path\to\mynetbeansproject\jni), put all the .dll, .so and .jnilib files in there (the native stuff), and add the following lines to the build.xml file you find in your project directory, just before the </project> tag:
<target name="-post-compile">
<copy todir="${dist.dir}/lib">
<fileset dir="jni" />
</copy>
</target>
then add the jar file to your project just like you always do. :)
the snippet you inserted in build.xml will make sure that the native libraries follow your jar files in the dist/lib folder when you invoke "Clean and Build" from within netbeans (or ant from the command line); the jvm will look for the .dll (.so, .jnilib) files in the same directory as the .jar that's loading them, so it will work.
note that this won't make your project run from within netbeans, becauseā€¦ I'm not really sure what goes on, but it looks like the library path (LD_LIBRARY_PATH) doesn't include your projects' libraries, and there's no way I know of changing it from within netbeans. just put your native libraries in /Library/Java/Extensions on mac os x, or just stash them in c:\windows\system32 under windows. if you're running a 64 bit windows with a 64 bit jvm, I have no clue; if you're running linux, you probably know where to stash them, but /usr/lib/java might be a good bet.
I tested the following solution while using NetBeans 7.0.1 and it worked, but I don't know if it works in early versions, too.
The solution is easy and works per NetBeans module. So, if you have a suite, don't place its JNI files into suite project, instead, place the JNI files that you want into the module itself. Do:
Find a NetBeans module project that you want (or need, or think) to place your JNI libraries (them with extension .DLL, .so and .jnilib, by eg);
At Projects, right click at the module node, click at Properties menu;
In the Project Properties dialog, click at Libraries and Wrapped JARs. You must add any external library there. I added the RxTX jar library. After add your external libraries, the Netbeans Ant script will copy all files/folders from the directory your_project_dir/release to the right location when you build the solution.
So, place your native libraries at your_project_dir/release/lib. If you want, you can create subdirectories for each target platform that you need, as: your_project_dir/release/lib/amd64, your_project_dir/release/lib/sparc32
To know, more, read:
http://bits.netbeans.org/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/api.html#jni
Regards,
marciowb.info

How can I reference ANT HOME from the libraries in the properties of a project when using eclipse?

In our code base we have a dependency on the ant version used in eclipse.
In the the ant.jar has been set up as a library which the project uses
This is a pain when moving versions of eclipse as the Ant plugin folder name changes (although I see it is now just called Ant1.7)
Is there a way to access eclipses reference to ANT Home which appears in the workspace preferences so that I don't have to explicitly set a variable that has the hard coded path to the ant plugins folder
Your project should not have a dependency on eclipse's version of Ant in the first place, you should keep your own version so as to decouple your project from eclipse. What if a developer or yourself decides to use intelliJ?
Although i don't know what the nature of your project is, i would have thought all dependencies should be added to your projects lib directory or something similar.
One possible suggestion would be to :
transform your project into a plugin project (properties on your project / PDE tools / convert Project to Plug-in Projects...) and
add to its dependencies the 'ant' required plugin.
That would be easier to manage when you change the version of eclipse.
Have you considered installing Ant separately, creating an environment variable, and then referencing the location via the ANT_HOME environment variable within your Ant build.xml?
From within your eclipse, on the package explorer view, right click on the specific project and build path.
Move into the Libraries tab and select the "Add Variable..." button. From here you'll see that is where the JDK system libraries path, maven(if you're using it, tomcat, eetc...) If ANT_HOME doesn't appear, you can add it by clicking the Configure Variables... button. From this moment, the ANT_HOME path will be considered in the build path of the project.
Hope it helps.
Carlos
Your ant home is available in the property ${ant.home}
E.g:
<echo> ${ant.home} </echo>
Gives the following on my machine:
[echo] D:\java\eclipse_3.4_jee\plugins\org.apache.ant_1.7.0.v200803061910