views:

262

answers:

1

Hello I have a WebApp with two dependencies as shown below. I would like to build a war file for deployment on Tomcat using Ant + Ivy.

+
+-MyWebApp // this Dynamic Java Web Application (deployed Tomcat and launches
           // a thread contained in MyApp) 
+-MyApp // this is just a vanilla Java Application
+-MyCommonStuff // these are common classes shared between MyApp and MyWebApp
                // Ex. Database access code & business classes

Using the Ant documentation I've worked out how to create the appropriate build.xml files for each project. In other words each project has an independent build.xml, so in order to build the whole project all I have to do is:

mkdir build
cd build
export SOME_COMMONBASE=`pwd`
svn co https://mybuildmachine.lan/svn/mycommonstuff mycommonstuff
cd mycommonstuff
ant
cd ..
% this produces mycommonstuff.jar
svn co https://mybuildmachine.lan/svn/myapp myapp
cd myapp
ant
cd ..
% this produces myapp.jar
svn co https://mybuildmachine.lan/svn/mywebapp mywebapp
cd mycommonstuff
ant
cd ..
% this produces mywebapp.war and deploys it to Tomcat

Now what I would like to do is bring it all together so that I can kick off a single build. On the surface it looks like I should somehow be able to create an Ivy build.xml which wires the dependencies together. However, I've read the Ivy documentation and Googled for examples but I'm still none-the-wiser about how I can accomplish this task. Can someone give me some pointers on how I can do this?

A: 

What you want to do is to use Ivy's Ant tasks for the wiring. There's quite a lot of finer details in there but basically you need your own Ivy repository and then just publish your own project artifacts there to use them elsewhere.

For JAR library projects:

  • Use ivy:retrieve to get the dependencies so that you can build the project into a library.
  • Use ivy:publish to publish the built JAR into your own Ivy repository.

For WAR projects:

  • Once again, use ivy:retrieve to get the dependencies so that you can build the project into a WAR.

As for other parts, Ant itself has many many tasks to help you and then there's some tasks provided by others such as svn task by tigris for getting the source from SVN and Ant's optional SCP task for transferring the WAR file to extenral server.

Esko