简体   繁体   中英

undeploy target not working properly

I am using tomcat6 and ant1.7.1. Trying out the cactus chapter in oreilly's java extreme programming book,I was trying to deploy ,undeploy a web app through tomcat manager using ant.

I wrote the deploy and undeploy targets using taskdefs as shown below.. When I run the deploy target ,the code gets compiled,made into war file and an empty directory called 'xptest' (the context name) is created at C:\\apache-tomcat-6.0.29\\work\\Catalina\\localhost. Ant outputs this message

[deploy] OK - Deployed application at context path /xptest

However,when the undeploy target is run ,I get only this message,

Buildfile: build.xml
init:
undeploy:
BUILD SUCCESSFUL
Total time: 0 seconds

When I check the manager appln in the browser ,I see that the application xptest is still deployed.Only when I click the undeploy button does it get removed. Why is this so? if someone can help me figure this out,please do

thanks

mark

The relevant part of the build file is given below

....
            <property environment="env."/>
    <property name="dir.build" value="build"/>
    <property name="dir.src" value="src"/>
    <property name="dir.resources" value="resources"/>
    <property name="dir.lib" value="lib"/>

    <property name="url.manager" value="http://localhost:8080/manager"/>
    <property name="username.manager" value="me"/>
    <property name="password.manager" value="mypasswd"/>
    <property name="host" value="http://localhost"/>
    <property name="port" value="8080"/>
    <property name="webapp.context.name" value="xptest"/>
            ....

<target name="init" description="sets properties if conditions are true">
        <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>

<target name="prepare" description="generate the cactus.properties file each time Cactus tests are run">
        <mkdir dir="${dir.build}"/>         
        <propertyfile file="${dir.build}/cactus.properties">
            <entry key="cactus.contextURL" value="${host}:${port}/

${webapp.context.name}"/>       
            <entry key="cactus.servletRedirectorName" value="${servlet.redirector}"/>
            <entry key="jspRedirectorName" value="${jsp.redirector}"/>
            <entry key="cactus.filterRedirectorName" value="${filter.redirector}"/>
        </propertyfile>
</target>

<target name="compile" depends="prepare" description="Compile all source code">
        <javac srcdir="${dir.src}" destdir="${dir.build}" verbose="yes">
            <classpath refid="classpath.project"/>
        </javac>
</target>

<target name="war" depends="compile">
        <war destfile="${dir.build}/${webapp.context.name}.war" 

webxml="${dir.resources}/web.xml">
            <classes dir="${dir.build}">
                <include name="com/oreilly/javaxp/cactus/**/*.class"/>
            </classes>          
             <lib dir="${env.CACTUS_HOME}/lib">
                <include name="aspectjrt-1.5.3.jar"/>
                <include name="cactus.core.framework.uberjar.javaEE.14-

1.8.1.jar"/>
                <include name="commons-logging-1.1.jar"/>
                <include name="httpunit-1.6.jar"/>
                <include name="junit-3.8.2.jar"/>
             </lib>         
            <fileset dir="${dir.resources}">
                  <include name="*.jsp"/>
                  <include name="*.html"/>
            </fileset>
        </war>
</target>

<target name="start.tomcat">
        <taskdef name="starttomcat"    

classname="com.oreilly.javaxp.tomcat.tasks.StartTomcatTask">
            <classpath>
                  <path location="${dir.lib}/tomcat-tasks.jar"/>
            </classpath>
        </taskdef>      
        <starttomcat testURL="${host}:${port}" catalinaHome="${env.CATALINA_HOME}"/>
</target>

<target name="undeploy" depends="init" if="is.webapp.deployed" description="Remove web application">
        <taskdef name="undeploy"  classname="org.apache.catalina.ant.UndeployTask">
            <classpath>
                 <path location="${env.CATALINA_HOME}/lib/catalina-ant.jar"/>
            </classpath>
        </taskdef>
        <undeploy url="${url.manager}" username="${username.manager}" 

password="${password.manager}"
                path="/${webapp.context.name}"/>
</target>

 <target name="deploy" depends="war,start.tomcat,undeploy" description="Install web application">   
        <taskdef name="deploy"    classname="org.apache.catalina.ant.DeployTask">
            <classpath>
                 <path location="${env.CATALINA_HOME}/lib/catalina-ant.jar"/>
            </classpath>
        </taskdef>
        <deploy url="${url.manager}" username="${username.manager}" 

password="${password.manager}"
                path="/${webapp.context.name}" war="file:${dir.build}/${webapp.context.name}.war"/>
</target>

I'm not entirely sure what might be wrong but it seems like it might be your condition for checking if the app is already deployed. You might try echoing what that gets set to when trying to undeploy.

May I also suggest the method described on the Tomcat documentation page for capturing the status of a context ? It's worked well for me. With the target named tomcat.context.status doing what's described there, you could then change your undeploy target to:

<target name="undeploy" depends="tomcat.context.status" unless="context.notInstalled" description="Remove web application">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM