更新了某個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