Just to add what @rai.shumar said, I've also had to find this one out recently. Here is what I've learnt so far.
References:
Firstly create a dir-structure:
- Create a "example" dir that will be your new project's root.
- create build dir
- create build/classes dir
- create dist dir
- create src dir
- create WEB-INF dir
- create WEB-INF/lib dir
then I added a few test files (by copying it from the apache tomcat examples)
- HelloMaster.java (renamed HelloWorldExample.java) to src/
- LocalString*.properties to WEB-INF/classes
- create an empty build.xml file in the "example"-dir
- create an empty web.xml file in the WEB-INF dir
The project structure should then look as follows:
~/example$ tree .
├── build
│ └── classes
│
├── build.xml
├── dist
│
├── src
│ └── HelloMaster.java
└── WEB-INF
├── classes
│ ├── LocalStrings_en.properties
│ ├── LocalStrings_es.properties
│ ├── LocalStrings_fr.properties
│ ├── LocalStrings.properties
│ └── LocalStrings_pt.properties
├── lib
└── web.xml
Then I've added the following to the WEB-INF/web.xml file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<servlet>
<servlet-name>HelloMaster</servlet-name>
<servlet-class>HelloMaster</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloMaster</servlet-name>
<url-pattern>/hellomaster</url-pattern>
</servlet-mapping>
</web-app>
the build.xml is the one with the most meat to it:
<?xml version="1.0" ?>
<project name="AntExample1" default="war">
<!-- hack! setting classpath explicitly to tomcat's classes -->
<!-- export CLASSPATH=$CLASSPATH:/path_to_apache_tomcat_classes/classes/ -->
<path id="compile.classpath">
<fileset dir="WEB-INF/lib">
<include name="*.jar"/>
</fileset>
</path>
<target name="init">
<mkdir dir="build/classes"/>
<mkdir dir="dist" />
</target>
<target name="compile" depends="init" >
<javac destdir="build/classes" debug="true" srcdir="src">
<classpath refid="compile.classpath"/>
</javac>
</target>
<target name="war" depends="compile">
<war destfile="dist/AntExample.war" webxml="WEB-INF/web.xml">
<fileset dir=""/>
<lib dir="WEB-INF/lib"/>
<classes dir="build/classes"/>
</war>
</target>
<target name="clean">
<delete dir="dist" />
<delete dir="build" />
</target>
</project>
Note I don't know how to set the classpath yet without setting it explicitly:
> export CLASSPATH=$CLASSPATH:/path_to_apache_tomcat_classes/classes/
> ant #-- this should create the war file in the dist dir
The war file should then be named dist/AntExample.war and you can copy it to your webapps directory