- To start with, make sure Tomcat manager is configured for use by Catalina-Ant. Make sure that
manager-scriptis included in the roles for one of the users inTOMCAT_HOME/conf/tomcat-users.xml. For example:<tomcat-users>
<user name="admin" password="s3cr£t" roles="manager-gui,manager-script"/>
</tomcat-users> - Catalina-Ant for Tomcat 6 was encapsulated within a single JAR file. Catalina-Ant for Tomcat 7 requires four JAR files. One from
TOMCAT_HOME/bin:tomcat-juli.jar
and three from TOMCAT_HOME/lib:catalina-ant.jar
tomcat-coyote.jar
tomcat-util.jar
There are at least three ways of making the JARs available to Ant:- Copy the JARs into the
ANT_HOME/libfolder. Then Ant will just find them. - Copy the JARs to a folder within your project that you check into your source control system. Ant then needs a path id to find them:
Where<path id="catalina-ant-classpath">
<fileset dir="${catalina-ant-dir}">
<include name="catalina-ant.jar"/>
<include name="tomcat-coyote.jar"/>
<include name="tomcat-util.jar"/>
<include name="tomcat-juli.jar"/>
</fileset>
</path>catalina-ant-diris the directory with the JARs in. This way you don’t need to modify the Ant installation on every machine you build on. - Access the JARs directly from your Tomcat 7 installation. Ant then needs a path id to find them:
Where<path id="catalina-ant-classpath">
<fileset dir="${appserver.lib}">
<include name="catalina-ant.jar"/>
<include name="tomcat-coyote.jar"/>
<include name="tomcat-util.jar"/>
</fileset>
<fileset dir="${appserver.home}/bin">
<include name="tomcat-juli.jar"/>
</fileset>
</path>appserver.libis the path to Tomcat 7’s lib directory andappserver.homeis the path to Tomcat’s top level installed directory. This way Tomcat 7 is required on every box you build on.
My personal preference is for 2 above. - Copy the JARs into the
- Now that your Ant script can see the Catalina-Ant JARs you need to tell it what tasks are available. These are most if not all of the tasks that are available to Ant.
<taskdef name="catalina-deploy" classname="org.apache.catalina.ant.DeployTask" classpathref="catalina-ant-classpath"/>
<taskdef name="catalina-list" classname="org.apache.catalina.ant.ListTask" classpathref="catalina-ant-classpath"/>
<taskdef name="catalina-reload" classname="org.apache.catalina.ant.ReloadTask" classpathref="catalina-ant-classpath"/>
<taskdef name="catalina-findleaks" classname="org.apache.catalina.ant.FindLeaksTask" classpathref="catalina-ant-classpath"/>
<taskdef name="catalina-resources" classname="org.apache.catalina.ant.ResourcesTask" classpathref="catalina-ant-classpath"/>
<taskdef name="catalina-start" classname="org.apache.catalina.ant.StartTask" classpathref="catalina-ant-classpath"/>
<taskdef name="catalina-stop" classname="org.apache.catalina.ant.StopTask" classpathref="catalina-ant-classpath"/>
<taskdef name="catalina-undeploy" classname="org.apache.catalina.ant.UndeployTask" classpathref="catalina-ant-classpath"/> - Finally you need a set of tasks that actually do the work. Although, as you can see above, there are a few tasks I only tend to use the following ones:
<target name = "stop-webapp">
<catalina-stop url="${tomcat.manager.url}"
username="${tomcat.username}"
password="${tomcat.password}"
path="/${webapp.name}"
failonerror="false"/>
</target>
<target name = "start-webapp">
<catalina-start url="${tomcat.manager.url}"
username="${tomcat.username}"
password="${tomcat.password}"
path="/${webapp.name}"/>
</target>
<target name = "undeploy-webapp">
<catalina-undeploy url="${tomcat.manager.url}"
username="${tomcat.username}"
password="${tomcat.password}"
path="/${webapp.name}"
failonerror="false"/>
</target>
<target name = "deploy-webapp">
<catalina-deploy url="${tomcat.manager.url}"
username="${tomcat.username}"
password="${tomcat.password}"
path="/${webapp.name}"
war="file:${war.file}"/>
</target>tomcat.manager.urlis the URL where Tomcat manager lives. This is another of the changes from Tomcat 6 to Tomcat 7. Usually this will be:http://.:8080/manager/text Tomcat.usernameandTomcat.passwordare the user name and password for Tomcat manager.webapp.nameis the name of the Tomcat application that you are deploying.war.fileis the path the Tomcat application you are deploying’s WAR file.
Thestop-webapptask has thefailonerrorattribute set tofalseas on most occasions you don’t want the Ant build to stop if a Tomcat application you’re trying to stop isn’t running.
I usually define all of these properties in a properties file that Ant can read. That way local settings can be picked up more easily if builds are run on different machines.
Wednesday, 9 November 2011
Catalina-Ant for Tomcat 7
I recently upgraded from Tomcat 6 to Tomcat 7 and all of my Ant deployment scripts stopped working. I eventually worked out why and made the necessary changes, but there doesn’t seem to be a complete description of how to use Catalina-Ant for Tomcat 7 on the web so I thought I'd write one.
Subscribe to:
Post Comments (Atom)

Thank you very much ! That was exactly what I needed.
ReplyDeleteThanks, very helpful when updating my tomcat to 7.0.26 today.
ReplyDeletePerfect! You might consider linking to stackoverflow:
ReplyDeletehttp://stackoverflow.com/questions/7251098/ant-tomcat-build-error-java-lang-noclassdeffounderror-org-apache-tomcat-util