How do I build a war file with Ant?
Author: Deron Eriksson
Description: This tutorial describes how to use Ant to build a war (web archive) file.
Tutorial created using: Windows XP || JDK 1.5.0_09 || Eclipse Web Tools Platform 1.5.1

Page: < 1 2 3 >

(Continued from page 1)

The 'tomcat-demo' project is shown below. It has a servletW class stored in a 'src' directory and a 'web' directory that contains WEB-INF, which contains web.xmlW. The WEB-INF directory contains a 'lib' directory that holds all jarW libraries needed by the project. The compiled classes are contained in the 'bin' directory. I added the build.xml file to the root level of the project.

tomcat-demo project

In EclipseSW, one way to invoke build.xml is to right-click on the build.xml file and go to Run As → AntSW Build.

invoke build.xml

Another way to invoke a build.xml file is to use the Ant view in Eclipse. In the Ant view, you can click on the 'Add Buildfiles' button.

Eclipse Ant View

In the Buildfile Selection window, I selected the tomcat-demo project's build.xml file and clicked OK.

Buildfile Selection window

After doing this, the tomcat-demo build.xml summary is shown graphically in the Ant view. The project name can be clicked on, which shows the various targets in build.xml. Below, we can see that warW is the only target for the tomcat-demo build.xml file.

To run the war target, we can select it and click the 'Run the Selected Target' button. We could also invoke it by double-clicking on the war target.

Run the Selected Target

(Continued on page 3)

Page: < 1 2 3 >