Shaun Abram
Java and Technology weblog
Ant build file to redeploy to Tomcat
Here is an example of an ant file that redeploys a web project to tomat. The neat thing is that as well as creating the war file, it also stops and restarts tomcat, all from ant.
I have found myself rewriting variations of this on a couple of projects recently, so I thought it was worth posting…
(Note it doesn’t include a compile target as I am doing it from my IDE)
<project name="{project.name}" basedir="." default="redeploy">
<property file="build.properties"/>
<target name="tomcat-stop">
<java jar="${tomcat.home}/bin/bootstrap.jar" fork="true">
<jvmarg value="-Dcatalina.home=${tomcat.home}"/>
<arg line="stop"/>
</java>
</target>
<target name="cleanTomcat" depends="tomcat-stop">
<delete dir="${project.deploydir}"/>
<delete file="${project.deploywar}"/>
</target>
<target name="createWar" depends="cleanTomcat">
<war destfile="${project.deploywar}" webxml="WEB-INF/web.xml">
<lib dir="WEB-INF/lib"/>
<classes dir="WEB-INF/classes"/>
<fileset dir="." includes="*.jsp" />
<fileset dir="WEB-INF"/>
</war>
</target>
<target name="tomcat-start">
<java jar="${tomcat.home}/bin/bootstrap.jar" fork="true">
<jvmarg value="-Dcatalina.home=${tomcat.home}"/>
</java>
</target>
<target name="redeploy" depends="createWar,tomcat-start"/>
</project>
And here is an example of the associated build.properties file
tomcat.home=C:/Program Files/Apache/tomcat
project.name=SampleProjectName
project.warfilename={project.name}.war
project.deploywar=${tomcat.home}/webapps/${project.name}.war
project.deploydir=${tomcat.home}/webapps/${project.name}
Subscribe to RSS Feed