彻底解决Ant在Tomcat进行卸载部署undeploy时不能删除jar文件的问题

彻底解决Ant在Tomcat进行卸载部署undeploy时不能删除jar文件的问题

首先有一种解决办法,就是在应用下的META-INF下新建context.xml:

<?xmlversion="1.0"encoding="UTF-8"?>

<Contextreloadable="true"antiResourceLocking="true"antiJARLocking="true">

</Context>

这种方法在重复进行多次deploy、undeploy时的确解决了该问题。但是如果在deploy和undeploy之间执行如下的webtest任务,也就是在undeploy前访问该应用,那么Tomcat就会加载jar文件,再执行undeploy时还是不能删除jar文件,此时似乎Tomcat植入jar根深蒂固了!

<targetname="webtest_login">

<echomessage="WebTest测试"/>

<execexecutable="cmd">

<argline="/cwebtest.bat-ftools/Java/webtest/login.xml-Dwebtest.home=${tools.webtest}"/>

<argline="-Dwebtest.home=${tools.webtest}"/>

<argline="-Dhost=${manager.ip}"/>

<argline="-Dport=${manager.port}"/>

<argline="-Dbasepath=${deploy.name}"/>

<argline="-Dresultpath=${report.webtestReport.part}"/>

<argline="-Dresultfile=${report.webtestReport.xml.part}"/>

</exec>

<xsltin="${report.webtestReport.xml}"out="${report.webtestReport.html}"style="${tools.webtest.reportstyle}"/>

</target>

有一个办法可以彻底解决该问题,就是使用xml部署文件来部署应用,不适用war发布的方式:

<targetname="deploy">

<echomessage="安装Web应用"/>

<taskdefname="deploy"classname="org.apache.catalina.ant.DeployTask"classpathref="classpath.catalina"/>

<deployurl="${manager.url}"username="${manager.username}"password="${manager.password}"path="/${deploy.name}"config="D:\AutoBuilder\build\student\web\context.xml"/>

</target>

context.xml描述的项目目录位于Tomcat外的目录:

<Contextpath="/student"docBase="D:/AutoBuilder/build/student/web"debug="0"/>

这样应用程序是指向外界的,不位于Tomcat目录中,再执行undeploy时就没有这个问题了。而且使用war进行deploy时后台的错误也不会再出现了:

java.io.FileNotFoundException:webapps\student(Thesystemcannotfindthepathspecified)

atjava.io.FileInputStream.open(NativeMethod)

atjava.io.FileInputStream.<init>(FileInputStream.java:106)

atorg.apache.catalina.startup.ExpandWar.copyInternal(ExpandWar.java:226)

BTW,deploy时会在C:\Tomcat5.5\conf\Catalina\localhost下拷贝生成context.xml,undeploy时会删除该文件。

ant

相关推荐