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
(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.
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.
In the Buildfile Selection window, I selected the tomcat-demo project's build.xml file and clicked OK.
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.
(Continued on page 3)