开发者

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. Mov开发者_JAVA技巧e 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

  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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜