DodoFXP
DodoFXP

Reputation: 483

Build eclipse project with ant

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

Upvotes: 14

Views: 29534

Answers (4)

davidfmatheson
davidfmatheson

Reputation: 3567

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?

Upvotes: 0

Tobber
Tobber

Reputation: 7541

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

  1. Create a ant file that jar the utility project. Follow: [1]
  2. Add it as a ant-builder to your utility project as described in [1]
  3. Now Eclipse will automatically generate the jar file every time you build.
  4. Extend the ant script to also copy to jar file to the lib dir.
  5. 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
  6. 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:

  1. You utility project will build first, because of the project reference
  2. The ant-builder will pack the jar, and copy it to the lib folder.
  3. 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

Upvotes: 0

Surej
Surej

Reputation: 358

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.

Upvotes: -1

Michael Spector
Michael Spector

Reputation: 37004

Does this wizard help

Rigth-click on project -> Export ... -> Ant buildfiles.

?

Upvotes: 19

Related Questions