gpt4 book ai didi

tomcat - 取消部署目标无法正常工作

转载 作者:行者123 更新时间:2023-11-28 23:52:46 25 4
gpt4 key购买 nike

我正在使用 tomcat6 和 ant1.7.1。试用 oreilly 的 java 极限编程书中的仙人掌章节,我试图通过使用 ant 的 tomcat 管理器部署、取消部署 Web 应用程序。

我使用 taskdef 编写了部署和取消部署目标,如下所示。当我运行部署目标时,代码被编译,制作成 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

当我在浏览器中检查 manager 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 documentation page for capturing the status of a context 中描述的方法吗? ?它对我来说效果很好。使用名为 tomcat.context.status 的目标执行此处描述的操作,然后您可以将 undeploy 目标更改为:

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

关于tomcat - 取消部署目标无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5919278/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com