[ Team LiB ] |
10.4 Removing a Web Application from Tomcat10.4.1 ProblemYou want to remove an old version of a web application without stopping and restarting Tomcat. 10.4.2 SolutionTomcat provides an Ant task called RemoveTask that removes a WAR file to Tomcat using Tomcat's Manager web application. 10.4.3 DiscussionBefore deploying a new version of a web application, Tomcat requires the current version of the web application be removed from the context path. This requirement is somewhat frustrating because the Ant build process must first ensure that the current web application is removed before trying to deploy; otherwise, the build process fails. Example 10-2 shows how to use Tomcat's RemoveTask, aptly named remove, to remove a web application from a given context path. A new target, undeploy, invokes the remove task. This target only executes if the property is.webapp.deployed is "true". The init target sets this property to "true" if there is a web application installed on the context path. Recipe 10.5 delves into how this is done. Example 10-2. Removing a web application from Tomcat<target name="undeploy" depends="init" if="is.webapp.deployed"> <taskdef name="remove" classname="org.apache.catalina.ant.RemoveTask"> <classpath> <path location="${env.CATALINA_HOME}/server/lib/catalina-ant.jar"/> </classpath> </taskdef> <remove url="${url.manager}" username="${username.manager}" password="${password.manager}" path="/${webapp.context.name}"/> </target> First, create a task definition so Ant knows about the remove task. The task is found at $CATALINA_HOME/server/lib/catalina-ant.jar, where $CATALINA_HOME is the base directory for Tomcat. Next, the remove task is executed and removes the web application from Tomcat on a specific context path. The remove task defines four attributes:
10.4.4 See AlsoRecipe 10.5 shows how to determine if Tomcat is started and if a web application is deployed on a given context path. |
[ Team LiB ] |