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 products 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 on this article are provided AS-IS. This means we've had reports of them working for some customers — under certain circumstances — yet 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 reach out to our Community for matters that fall beyond 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:

1 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 applicationtask fails and the logs contain the following error:

1 2 3 4 5 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 /hello

Cause

This is more common in Windows OS where Tomcat might lock files or directory locations. In most cases, this happens after the first successfull 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 appplied.

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.

Updated on April 8, 2025

Still need help?

The Atlassian Community is here for you.