tomcat 7 undeploy fails dues log4j.properties

1.8k Views Asked by At

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>
3

There are 3 best solutions below

1
Stefan On

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

2
Mark Thomas On

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

0
user2754571 On

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.