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

首先有一种解决办法,就是在应用下的META-INF下新建context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Context reloadable="true" antiResourceLocking="true" antiJARLocking="true">
</Context>

 

这种方法在重复进行多次deploy、undeploy时的确解决了该问题。但是如果在deploy和undeploy之间执行如下的webtest任务,也就是在undeploy前访问该应用,那么Tomcat就会加载jar文件,再执行undeploy时还是不能删除jar文件,此时似乎Tomcat植入jar根深蒂固了!
<target name="webtest_login">
 <echo message="WebTest测试"/>
 <exec executable="cmd">
  <arg line="/c webtest.bat -f tools/Java/webtest/login.xml -Dwebtest.home=${tools.webtest}"/>
  <arg line="-Dwebtest.home=${tools.webtest}"/>
  <arg line="-Dhost=${manager.ip}"/>
  <arg line="-Dport=${manager.port}"/>
  <arg line="-Dbasepath=${deploy.name}"/>
  <arg line="-Dresultpath=${report.webtestReport.part}"/>
  <arg line="-Dresultfile=${report.webtestReport.xml.part}"/>
 </exec>
 <xslt in="${report.webtestReport.xml}" out="${report.webtestReport.html}" style="${tools.webtest.reportstyle}" />
</target>

 

有一个办法可以彻底解决该问题,就是使用xml部署文件来部署应用,不适用war发布的方式:
<target name="deploy">
 <echo message="安装Web应用"/>
 <taskdef name="deploy"   classname="org.apache.catalina.ant.DeployTask" classpathref="classpath.catalina"/>
 <deploy url="${manager.url}" username="${manager.username}" password="${manager.password}" path="/${deploy.name}" config="D:/AutoBuilder/build/student/web/context.xml"/>
</target>

 

context.xml描述的项目目录位于Tomcat外的目录:
<Context path="/student" docBase="D:/AutoBuilder/build/student/web" debug="0"/>

 

这样应用程序是指向外界的,不位于Tomcat目录中,再执行undeploy时就没有这个问题了。而且使用war进行deploy时后台的错误也不会再出现了:
java.io.FileNotFoundException: webapps/student (The system cannot find the path specified)
 at java.io.FileInputStream.open(Native Method)
 at java.io.FileInputStream.<init>(FileInputStream.java:106)
 at org.apache.catalina.startup.ExpandWar.copyInternal(ExpandWar.java:226)

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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值