Tomcat allows a web application to be deployed, undeployed, and reloaded while the container is still running. The following changes to the build.xml file allow for a tomcat-install, tomcat-reload, and tomcat-remove targets.
These changes assume that Tomcat 5.0.19 has been installed on the local computer. Tomcat can be found here
http://jakarta.apache.org/tomcat. To enable the Tomcat ant task, the file server/lib/catalina-ant.jar must be place in the lib directory of your ant install. This is documented in the Tomcat documentation.
The following changes are made to the build.xml to enable the tomcat-install, tomcat-reload targets. While developing, the tomcat-install target is executed once. The tomcat-reload target is executed each time the application needs to be recompiled and tested. These targets use the web application created in the cls/webapp directory, so be careful with the clean target.
Add these lines near the top of the build.xml
<property name="manager.url" value="http://localhost:8080/manager" />
<property name="manager.username" value="admin" />
<property name="manager.password" value="tomcat" /> <taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask" />
<taskdef name="list" classname="org.apache.catalina.ant.ListTask" />
<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask" />
<taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask" />Rename the snipsnap-war target to prepare-snipsnap-war, and remove the last task that makes the war file. then add the following target after the prepare-snipsnap-war target.
<!-- jar up the web application template -->
<target depends="prepare-snipsnap-war"
description="build template war"
name="snipsnap-war">
<jar destfile="${jar}/${appname}.war">
<fileset dir="${target}/webapp" includes="**" />
</jar>
</target>Add these targets near the bottom of the build.xml
<target depends="prepare-snipsnap-war"
description="manager install to tomcat"
name="tomcat-install">
<deploy url="${manager.url}"
username="${manager.username}"
password="${manager.password}"
path="/${appname}"
localWar="file://${target}/webapp" />
</target> <target depends="prepare-snipsnap-war"
description="manager reload to tomcat"
name="tomcat-reload">
<reload url="${manager.url}"
username="${manager.username}"
password="${manager.password}"
path="/${appname}" />
</target> <target name="tomcat-list"
description="List installed applications on servlet container">
<list url="${manager.url}"
username="${manager.username}"
password="${manager.password}" />
</target> <target name="tomcat-remove" description="Remove snipsnap from tomcat">
<undeploy url="${manager.url}"
username="${manager.username}"
password="${manager.password}"
path="/${appname}" />
</target>