Deploying artifacts to Tomcat with Bamboo Data Center will sometimes fail due to file locking: Unable to delete
Platform Notice: Data Center Only - This article only applies to Atlassian apps on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
The steps outlined in this article are provided AS-IS. This means we've had reports of them working for some customers, under certain circumstances, yet they are not officially supported, nor can we guarantee they'll work for your specific scenario.
You may follow through and validate them on your own non-prod environments prior to production, or fall back to supported alternatives if they don't work out.
We also invite you to contact our Community for matters that are outside Atlassian's scope of support!
When using the Deploy Tomcat application task to deploy the generated artifacts to Tomcat, the build fails with the below error in the build logs:
Application failed to deploy: FAIL - Unable to delete [D:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\hello]. The continued presence of this file may cause problems.Environment
The solution has been validated in Bamboo 5.7.2 but may be applicable to other versions.
Diagnosis
The build plan with a Deploy Tomcat application task fails, and the logs contain the following error:
Starting task 'Deploy test' of type 'com.atlassian.bamboo.plugins.tomcat.bamboo-tomcat-plugin:deployAppTask'
Deploying application with war file 'test.war' to context '/hello' to server 'http://localhost:8080/manager/'
...
Application failed to deploy: FAIL - Unable to delete [D:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\hello]. The continued presence of this file may cause problems.
FAIL - Application already exists at path /helloCause
This is more common in Windows OS, where Tomcat might lock files or directory locations. In most cases, this happens after the first successful deployment, and subsequent ones might get blocked.
Even though this is more common in Windows, it might affect OSs based on Unix as well, and the same solution can be applied.
Solution
This can be prevented/fixed by adding <Context antiResourceLocking="true"> to Tomcat's context file (<tomcat-home>/conf/context.xml) and restarting the Tomcat service. The antiResourceLocking is set to false by default.
More details can be found in the Tomcat 7.0 documentation.
Additionally, if your Tomcat servlet opens files (for example, through the Scanner class), ensure the files are properly closed as well. Not closing application files after opening them through your servlet can interfere with Tomcat's ability to delete files during undeployment, especially in the WEB-INF/classes directory.
For further support or inquiries, please review the Tomcat documentation and/or reach out to Tomcat support.
Was this helpful?