Grab the catalina-ant.jar from the xammp/tomcat/lib directory, place it in JP/lib, and update the build path to include that jar. ant-contrib-0.3.jar from http://ant-contrib.sourceforge.net
To build.properties
server.base
= http://localhost
server.port = 8080
server.url = ${server.base}:${server.port}
server.manager.url = ${server.url}/manager
server.manager.username = xampp
server.manager.password = xampp
server.manager.pause = 5
webapp.path = /${ant.project.name}
server.port = 8080
server.url = ${server.base}:${server.port}
server.manager.url = ${server.url}/manager
server.manager.username = xampp
server.manager.password = xampp
server.manager.pause = 5
webapp.path = /${ant.project.name}
in build.xml
<path id="classpath">
[...]
</path>
<!-- ==========================================================
Define the tomcat (catalina) tasks from catalina-ant.jar
for ant.
========================================================== -->
<taskdef name="install" classname="org.apache.catalina.ant.InstallTask" classpathref="classpath" />
<taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask" classpathref="classpath" />
<taskdef name="list" classname="org.apache.catalina.ant.ListTask" classpathref="classpath" />
<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask" classpathref="classpath" />
<taskdef name="remove" classname="org.apache.catalina.ant.RemoveTask" classpathref="classpath" />
<taskdef name="resources" classname="org.apache.catalina.ant.ResourcesTask" classpathref="classpath" />
<taskdef name="roles" classname="org.apache.catalina.ant.RolesTask" classpathref="classpath" />
<taskdef name="start" classname="org.apache.catalina.ant.StartTask" classpathref="classpath" />
<taskdef name="stop" classname="org.apache.catalina.ant.StopTask" classpathref="classpath" />
<taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask" classpathref="classpath" />
<!-- ==========================================================
Define ant-contrib tasks. Used for if/then,try/catch
and other smart ant tasks
========================================================== -->
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="classpath" />
[...]
<!-- ==========================================================
all
Run all core tasks
========================================================== -->
<target name="all" [...]>
[...]
<!-- IMPLIED
[...]
<antcall target="war"/>
-->
[...]
</target>
[...]
<!-- =========================================================
Tomcat management targets
========================================================= -->
<!-- ==========================================================
install
install the web application (requires that no application
is already running)
========================================================== -->
<target name="install" description="Install web application" depends="war">
<echo level="info">
***********************************************************************
*
* Attempting to install ${webapp.name} to ${server.url}${webapp.path}
*
***********************************************************************
</echo>
<!-- this task fails if an application already exists -->
<trycatch property="install.error">
<try>
<deploy url="${server.manager.url}"
path="${webapp.path}"
war="${dir.build.war}/${webapp.name}"
username="${server.manager.username}"
password="${server.manager.password}" />
<echo>Installation succesfful</echo>
<echo level="info">
***********************************************************************
*
* Pausing for ${server.manager.pause} for the server to load pages
*
***********************************************************************
</echo>
<sleep seconds="${server.manager.pause}"/>
</try>
<catch>
<echo level="warning">Received error ${install.error}</echo>
<!-- do some other tasks here later to remedy -->
</catch>
</trycatch>
</target>
[...]
</path>
<!-- ==========================================================
Define the tomcat (catalina) tasks from catalina-ant.jar
for ant.
========================================================== -->
<taskdef name="install" classname="org.apache.catalina.ant.InstallTask" classpathref="classpath" />
<taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask" classpathref="classpath" />
<taskdef name="list" classname="org.apache.catalina.ant.ListTask" classpathref="classpath" />
<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask" classpathref="classpath" />
<taskdef name="remove" classname="org.apache.catalina.ant.RemoveTask" classpathref="classpath" />
<taskdef name="resources" classname="org.apache.catalina.ant.ResourcesTask" classpathref="classpath" />
<taskdef name="roles" classname="org.apache.catalina.ant.RolesTask" classpathref="classpath" />
<taskdef name="start" classname="org.apache.catalina.ant.StartTask" classpathref="classpath" />
<taskdef name="stop" classname="org.apache.catalina.ant.StopTask" classpathref="classpath" />
<taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask" classpathref="classpath" />
<!-- ==========================================================
Define ant-contrib tasks. Used for if/then,try/catch
and other smart ant tasks
========================================================== -->
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="classpath" />
[...]
<!-- ==========================================================
all
Run all core tasks
========================================================== -->
<target name="all" [...]>
[...]
<!-- IMPLIED
[...]
<antcall target="war"/>
-->
[...]
</target>
[...]
<!-- =========================================================
Tomcat management targets
========================================================= -->
<!-- ==========================================================
install
install the web application (requires that no application
is already running)
========================================================== -->
<target name="install" description="Install web application" depends="war">
<echo level="info">
***********************************************************************
*
* Attempting to install ${webapp.name} to ${server.url}${webapp.path}
*
***********************************************************************
</echo>
<!-- this task fails if an application already exists -->
<trycatch property="install.error">
<try>
<deploy url="${server.manager.url}"
path="${webapp.path}"
war="${dir.build.war}/${webapp.name}"
username="${server.manager.username}"
password="${server.manager.password}" />
<echo>Installation succesfful</echo>
<echo level="info">
***********************************************************************
*
* Pausing for ${server.manager.pause} for the server to load pages
*
***********************************************************************
</echo>
<sleep seconds="${server.manager.pause}"/>
</try>
<catch>
<echo level="warning">Received error ${install.error}</echo>
<!-- do some other tasks here later to remedy -->
</catch>
</trycatch>
</target>
Make sure your application is undeployed by logging into the manager and doing so manually. Then let's test everything out.
>
ant svn zip install
[...]
install:
[echo]
[echo] ***********************************************************************
[echo] *
[echo] * Attempting to install JavaPersistence.war to http://localhost:8080/JavaPersistence
[echo] *
[echo] ***********************************************************************
[echo]
[deploy] OK - Deployed application at context path /JavaPersistence
[echo] Installation succesfful
[echo]
[echo] ***********************************************************************
[echo] *
[echo] * Pausing for 5 for the server to load pages
[echo] *
[echo] ***********************************************************************
[echo]
BUILD SUCCESSFUL
Total time: 24 seconds
[...]
install:
[echo]
[echo] ***********************************************************************
[echo] *
[echo] * Attempting to install JavaPersistence.war to http://localhost:8080/JavaPersistence
[echo] *
[echo] ***********************************************************************
[echo]
[deploy] OK - Deployed application at context path /JavaPersistence
[echo] Installation succesfful
[echo]
[echo] ***********************************************************************
[echo] *
[echo] * Pausing for 5 for the server to load pages
[echo] *
[echo] ***********************************************************************
[echo]
BUILD SUCCESSFUL
Total time: 24 seconds
And now to see what happens if we try to install with an application already there
>
ant install
[...]
install:
[echo]
[echo] ***********************************************************************
[echo] *
[echo] * Attempting to install JavaPersistence.war to http://localhost:8080/JavaPersistence
[echo] *
[echo] ***********************************************************************
[echo]
[deploy] FAIL - Application already exists at path /JavaPersistence
[trycatch] Caught exception: FAIL - Application already exists at path /JavaPersistence
[echo] Received error FAIL - Application already exists at path /JavaPersistence
BUILD SUCCESSFUL
Total time: 3 seconds
[...]
install:
[echo]
[echo] ***********************************************************************
[echo] *
[echo] * Attempting to install JavaPersistence.war to http://localhost:8080/JavaPersistence
[echo] *
[echo] ***********************************************************************
[echo]
[deploy] FAIL - Application already exists at path /JavaPersistence
[trycatch] Caught exception: FAIL - Application already exists at path /JavaPersistence
[echo] Received error FAIL - Application already exists at path /JavaPersistence
BUILD SUCCESSFUL
Total time: 3 seconds
The 'successful' part is obviously false, but we now have the ability to try another task (that we'll provide next) to remove the application. For now, this is perfect.
>
ant svn inc.build.minor
commit
Deploying Webapps with Ant