更新了某个webapp,把新的WAR包放到webapps目录下,Tomcat就会自动把原来的同名webapp删除,并把WAR包解压,运行新的webapp。但是,有时候Tomcat并不能把旧的webapp完全删除,通常会留下WEB-INF/lib下的某个jar包,必须关闭Tomcat才能删除,这就导致自动部署失败。
解决方法是在<Context>元素中增加一个属性
antiResourceLocking="true",默认是"false"。但是这样会带来一个问题,Tomcat在运行对应的webapp时,会把下面的文件复制到一个临时目录里,所以如果你在服务器运行的时候修改了某个JSP,Tomcat并不会发现,看到的还是修改前的那个页面。
Context elements may be explicitly defined:
- in the
$CATALINA_HOME/conf/context.xml
file: the Context element information will be loaded by all webapps
- in the
$CATALINA_HOME/conf/[enginename]/[hostname]/context.xml.default
file: the Context element information will be loaded by all webapps of that host
- in individual files (with a ".xml" extension) in the
$CATALINA_HOME/conf/[enginename]/[hostname]/
directory. The name of the file (less the .xml) extension will be used as the context path. Multi-level context paths may be defined using #, e.g. context#path.xml
. The default web application may be defined by using a file called ROOT.xml
.
- if the previous file was not found for this application, in an individual file at
/META-INF/context.xml
inside the application files
- inside a Host element in the main
conf/server.xml
参考资料:
Tomcat 5.5 文档:
http://tomcat.apache.org/tomcat-5.5-doc/config/context.html关于antiResourceLocking的bug:
http://issues.apache.org/bugzilla/show_bug.cgi?id=37668