Tobia
Tobia

Reputation: 9526

Tomcat WAR file deploy failure in Windows

I have an application running in a tomcat container in Windows environment. When I have to update the application, the tomcat windows service is stopped, new ROOT.war file is copied in the webapps folder and tomcat service is restarted.

Sometimes it happens that the ROOT.war extraction fails and the extracted ROOT folder has only few subfolder and few files. Obviously the following application startup fails. To solve this problem I have to stop tomcat, delete ROOT folder and run in again to let tomcat re-extract the ROOT.war again from the beginning.

I cannot understand why sometimes it happens and sometimes no. However, it makes impossibile to me to create an automatic update. It is too risky.

Do you have any idea why it can happen?

Upvotes: 0

Views: 1845

Answers (2)

Piotr P. Karwasz
Piotr P. Karwasz

Reputation: 16185

Remark: if you are updating the application while Tomcat is running you need to either:

  • use Tomcat Manager to deploy it,
  • call tryAddServiced (before Tomcat 9.0 addServiced/isServiced) before any modification to the webapps directory and removeServiced afterwards. This can be done through JMX on the bean Catalina:type=Deployer,host=<your_host_name>,
  • replace the WAR file (almost) atomically: e.g. deleting the old one and moving (renaming) the new one from another location on the same filesystem should work.

which prevents Tomcat from immediately deploying the application until the copy operation is finished.

To prevent the OS from locking the files in the webapps/ROOT folder you have two options:

  1. Use antiResourceLocking="true" as already suggested by Svetlin, which basically forces Tomcat to copy webapps/ROOT to a uniquely named temporary directory before deployment (the copy will be locked, webapps/ROOT will not),
  2. Use parallel deployment by naming your WAR files: ROOT##001.war, ROOT##002.war, etc. This is basically an explicit version of the antiResourceLocking feature with the additional advantage of letting clients transition fluently between the old and new app version.

Upvotes: 0

digvijaykatoch
digvijaykatoch

Reputation: 141

Resources are not released. So, when you try to update the existing war file, tomcat is not able to delete the older files before deployment/redeployment.

To resolve this issue, ensure that:

  1. The application is not open/running on web browser.
  2. You're not stuck in debug mode when you click on update.
  3. All processes/requests are completed before redeployment.
  4. All files/streams are closed within the code.
  5. When all else fails, you may want to stop the application. Then update. There are ways to stop applications on tomcat using command line, batch files, etc. You can then automate the process.

If you want a more reliable way to do this, you may use jrebel or a free version of the same. There are other ways to update code. Basically, standalone tomcat is not worth anything more than a development server.

Upvotes: 1

Related Questions