1

This error is quite puzzling. In my webapps, I have the log4j.properties in WEB-IF/classes as per recommendation.

When I deploy from eclipse, I do a stop on the webapp, undeploy, and then deploy. Strangely enough, 8 out of 10 times I get the following error on undeploy-
build.xml:526: FAIL - Unable to delete [C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\punch]. The continued presence of this file may cause problems.

The only file remaining under my webapp is the WEB-INF/classes/log4j.properties. Everything else is deleted.

I cannot manually delete the file or the webapp folder either. I have to stop Tomcat service, delete the folder and then restart.

Is there any solution for this?

Thanks.

Here is my remove task in build.xml

<target name="remove"
 description="Remove application on servlet container">

<stop url="${manager.url}"
     username="${manager.username}"
     password="${manager.password}"
         path="${app.path}"/>

<undeploy url="${manager.url}"
     username="${manager.username}"
     password="${manager.password}"
         path="${app.path}"/>

</target>
user2754571
  • 251
  • 3
  • 14
  • Tomcat has some file locking issues. I've seen this many times, but I've never found a solution. – Ian McLaird Oct 10 '13 at 17:34
  • Tomcat does not have any known file locking issues. Plenty of third party libraries do have issues and Tomcat jumps through a number of hoops to work around known issues where it can. The solution is to identify what is holding the lock on the file via a profiler and then figure out how to get it to release. That may require a bug report against the library to provide a shutdown() type method. – Mark Thomas Oct 10 '13 at 20:32

3 Answers3

0

That's because the file is opened for reading. You need to at least shutdown your app. That can easily be done with PsiProbe.

Stefan
  • 12,108
  • 5
  • 47
  • 66
0

Make sure you call LogManager.shutdown() in the contextDestroyed() method of a ServletContextListener. That should ensure that log4j doesn't have the file open.

Mark Thomas
  • 16,339
  • 1
  • 39
  • 60
0

Here is my work around:

I created another target to copy the war to Tomcat's webapp directory.

<target name="copywar" depends="dist">
    <copy file="${dist.home}/${app.name}.war" todir="${catalina.home}/webapps" />
</target>

I also made sure that Tomcat could redeploy with this in server.xml

<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">

This works just fine. Thanks for your help folks.

user2754571
  • 251
  • 3
  • 14