[ Team LiB ] |
10.5 Checking If a Web Application Is Deployed10.5.1 ProblemYou need to check if a web application is installed on a particular context path. 10.5.2 SolutionCreate an Ant target that sets a property if a given context path contains an installed web application. This target should execute before trying to remove the web application. 10.5.3 DiscussionTomcat's Manager application fails when trying to remove a web application that does not exist. It's frustrating because the Ant build process must check if the web application is installed before attempting to remove it. Luckily, the solution is simple. Example 10-3 shows an init target that checks if the web application is installed on a given context path. The init target sets two properties: is.tomcat.started and is.webapp.deployed. The condition task sets is.tomcat.started to "true" if the nested subtask http returns a valid HTTP response code.[1] The condition task sets is.webapp.deployed to "true" if Tomcat is started and the nested http subtask returns a valid response code. A valid response code means that some type of success occurred when opening a connection to the URL. If a failure occurs, the URL is assumed to be invalid.
Example 10-3. Checking if a web application exists on a given context path<target name="init"> <condition property="is.tomcat.started"> <http url="${host}:${port}"/> </condition> <condition property="is.webapp.deployed"> <and> <isset property="is.tomcat.started"/> <http url="${host}:${port}/${webapp.context.name}"/> </and> </condition> </target> 10.5.4 See AlsoRecipe 10.4 discusses how to use Tomcat's Manager application to remove a web application from a context path. |
[ Team LiB ] |