Tomcat webapp folder is ruined when putting a new war file

夙愿已清 提交于 2020-01-05 04:24:11

问题


Usually, when I put an updated WAR file in Tomcat's webapps folder, the appropriate webapp is automatically updated.

But sometimes, when I put in an updated WAR file, a strange thing happens: most of that webapp's folder is deleted, except some random collection of files. Of course in this case the webapp no longer works. To make it work, I must stop Tomcat, delete the folder of that webapp entirely, then restart Tomcat.

I tried to stop the webapp from the Tomcat manager before putting the WAR file in webapps - it didn't help.

I tried to change autodeploy and/or unpackwars to false, but then the webapp was not updated at all when I put in the new warfile.

I also tried to use Jenkins' deployment plugin, but the same problem happened.

System spec: Tomcat 7 on Windows 2003.


回答1:


According to Tomcat 7 configuration guide: http://tomcat.apache.org/tomcat-7.0-doc/config/host.html#Automatic%20Application%20Deployment

"Updating a WAR file will trigger an undeploy of the application, with the removal of any associated expanded directory, context file and work directory. Any current user sessions will not be persisted... The application will be redeployed the next time the auto deployer checks for changes."

Probably, the problem is that the auto-deployer still hasn't finished to remove the expanded directory, while another thread started re-deploying it.

My workaround is to delete the old war-file, wait until the directory is removed, and only then put the new war-file, since:

"Deleting a WAR file will trigger an undeploy of the application, with the removal of any associated expanded directory, context file and work directory. Any current user sessions will not be persisted."




回答2:


Sounds like "antiResourceLocking"

Disclaimer: 1. Yes, I know this is an old question. 2. Completely untested.

I have not tried this, so this is untested purely "by the books" stuff. Here goes.

The Tomcat7 documentation (archived here) at least mentions that you need extra steps for hot deploy on Windows. Namely...

on Windows, this assumes that anti-locking features (see Context configuration) are enabled, otherwise it is not possible to delete the resources of a running web application.

...and the appropriate configuration switch seems to be something called antiResourceLocking, which apparently...

allows full webapp hot deploy and undeploy on platforms or configurations where file locking can occur

(Source here. Archived here.)

And I'm not sure, but all of this does indeed sound a bit like "undefined behavior can happen if you try to hot-deploy on Windows WITHOUT antiResourceLocking=true". And that sounds just terrible.

Further reading

  • Matrix. Judging by the matrix in the documentation, I think it's quite complicated.
    (So my personal bottom line here is: I will just NOT use automatic-deployment, unless I absolutely have to. And rather do what you did and manually delete DIRs and unpack WARs.)
    • https://tomcat.apache.org/tomcat-7.0-doc/config/automatic-deployment.html#New_files
      (Archived here.)


来源:https://stackoverflow.com/questions/9896102/tomcat-webapp-folder-is-ruined-when-putting-a-new-war-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!