Using Ant

Using ANT for Application Development

When using ANT, your Web application is edited and compiled in a directory that is external to the base of Tomcat ($CATALINA_BASE). In order to use ANT for your application developement, do the following:

  1. Define a working directory. For example, ~/dbi/ex5).
  2. Create a Web-application directory under your working directory. For example, this directory may be ~/dbi/ex5/dbinfo.
  3. Copy the file ~dbi/tomcat/ant/build.xml into your working directory. For example:
    > cp ~dbi/tomcat/ant/build.xml ~/dbi/ex5
  4. Edit the file build.xml. Your will typically have to change the following properties:

Now a working directory is set for ANT and you can start your developement.

Files you create for your application should be located as if your application directory was located under $CATALINA_HOME/webapps/. This means that static resources and JSP are accessible from everywhere under your applicatiomn directory (except for WEB-INF) and Java classes should be under WEB-INF/classes/.

Place your Java source files under WEB-INF/src/.

To compile your Java classes and JSP files, go to ANT working directory and execute (from the Unix shell):
> ant compile

To execute the follwing, Tomcat must be up.

To deploy your Web-application, execute:
> ant deploy

To delete all class files (and project WAR) exeute:
> ant clean

To stop/start/reload your deployed Web-application execute:
> ant stop > ant start > ant reload

In the following image, you can see an example of creating a complete Web application using ANT. It is important to note that Tomcat runs when the code is executed. ANT execution example

You may (and are encouraged to) change the file build.xml to suit your preferences. For example, you may add a target that launches emacs with your README file.

Note: ANT and JSP

If you have JSP files under your application directory, ANT will translate these files into Servlets and will compile them (when invoking its "compile" target). In addition, ANT will update your web.xml file to map requests for your JSP files into their corresponding Servlets. The result of this is that Tomcat ignores the JSP files in your deployed application, and changes you make in these files will not be reflected. Therefore, reflecting changes in JSP files require both compiling and deploying your application using ANT.