【发布时间】:2011-08-20 15:05:26
【问题描述】:
我正在使用 tomcat6 和 ant1.7.1。 尝试了oreilly的java极限编程书中的仙人掌章节,我正在尝试使用ant通过tomcat管理器部署,取消部署一个Web应用程序。
我使用 taskdefs 编写了部署和取消部署目标,如下所示。 当我运行部署目标时,代码被编译,制作成 war 文件,并在 C:\apache-tomcat-6.0.29\work\Catalina\localhost 创建一个名为“xptest”(上下文名称)的空目录。 Ant 输出这条消息
[deploy] OK - Deployed application at context path /xptest
但是,当运行取消部署目标时,我只收到此消息,
Buildfile: build.xml
init:
undeploy:
BUILD SUCCESSFUL
Total time: 0 seconds
当我在浏览器中检查管理器 appln 时,我看到应用程序 xptest 仍在部署。只有当我单击取消部署按钮时,它才会被删除。 为什么会这样?如果有人可以帮我解决这个问题,请做
谢谢
标记
下面给出了构建文件的相关部分
....
<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>
【问题讨论】:
标签: tomcat deployment ant