My Windows Ant/Tomcat web application build process

I don't like the off-the-shelf process of developing web applications with Ant and Tomcat on Windows computers. Rather than get into my angst, here's the way I think the Ant build process should work with Tomcat:

  • You build your web application with Ant.
  • If the build process succeeds Ant cleans out your Tomcat directory structure -- including the old application directory and all log files -- and then automatically starts the Tomcat application server.

This doesn't happen with Ant and Tomcat off the shelf -- you always have to do things manually, whether you're using Eclipse or working from the command line.

To solve this problem I've created my own Ant tasks and batch files that I use on Windows computers. Now, whenever I want to build my web application, deploy it, clean out my Tomcat folders, and start the Tomcat server, I just issue this command from my build directory:

ant t-deploy

The code shown below from my Ant build script (build.xml) shows how this works:

<property name="tomcat.home" value="${env.TOMCAT_HOME}" />
<property name="" value="${}" />

<target name="t-deploy" 
        depends="install, t-start" 
        description="FULL DEPLOY OF THE WEB APP">
<target name="t-start" depends="delete-logs, delete-deploy-dir">
  <echo>=== STARTING TOMCAT ===</echo>
  <sleep milliseconds="250"/>
  <exec executable="cmd">
    <arg value="/c"/>
    <arg value="${tomcat_start_script}"/>

<target name="delete-logs">
  <echo>=== DELETING LOG FILES ===</echo>
    <fileset dir="${tomcat.home}/logs/" includes="*.log"/>

<target name="delete-deploy-dir">
  <echo>=== REMOVING OLD DEPLOY DIRECTORY ===</echo>
  <delete dir="${war_deployment_dir}/${}" />


As you can see, the t-deploy task first runs the install task, then runs the t-start task. The t-start task depends on two other tasks, delete-logs, and delete-deploy-dir. The logs directory is something like C:\tomcat-6.0.16\logs, and the deploy directory is something like C:\tomcat-6.0.16\webapps\MyWebApplication.

This Ant/Tomcat integration approach depends on a Windows batch script which I named tomcat-start.bat and I keep in the same directory as my build.xml file. Here's the contents of that script:

REM A special script to help startup tomcat from within 
REM the Ant build process.

SET TOMCAT_HOME=C:\tomcat-6.0.16
SET CATALINA_HOME=C:\tomcat-6.0.16