6

Synopsis

I am attempting to export a WAR to my webapps folder but everytiime I update the war it deletes all of the content of the webapp minus /WEB-INF/lib/struts.jar

System info

  • Windows 2K3
  • Tomcat 5.5
  • JRE 1.6.23

Ok here is what is happening:

  1. Export project as .WAR via Eclipse (Helios) to /webapps directory
  2. Tomcat sees the change in the war and attempts to rebuild webapp
  3. Tomcat deletes contents of webapp folder (/webapps/public)
  4. (/webapps/public/WEB-INF/lib/struts.jar) is locked preventing it from being deleted.
  5. Tomcat gives up rebuild leaving me with nothing in the folder besides the struts.jar causing the application to break.

Question(s)

  • Is there a way to keep the jar from being locked?
  • (OR) a better deployment process I should be using (and can pick up quickly)?

Using antiResourceLocking="true" and antiJARLocking="true" on the <Context> element did not solve the problem. Appreciate any help.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
PseudoNinja
  • 2,846
  • 1
  • 27
  • 37

4 Answers4

4

Does adding unloadDelay to your Context help?

Which is the:

Amount of ms that the container will wait for servlets to unload. If not specified, the default value of the flag is 2000 ms.

Source: http://tomcat.apache.org/tomcat-5.5-doc/config/context.html

Apparently sometimes the web app is in the middle of a large GC / the ClassLoader hasn’t been garbage collected and cannot release in time. Try experimenting with the timeout to see if that helps.

There is also some anecdotal evidence of strange file locking on Windows platforms.

Also, assuming you're referring to a development (not production) build environment, look at one of my questions, showing my approach to Tomcat / Eclipse hot deploy environments:

Tomcat and Eclipse Zero Turnaround Deployment


Update

This helpful thread comes up on a Google search of the same issue and is referred to by a number of others:

http://blog.exis.com/colin/?s=I+Put+A+Spell+On+You

Community
  • 1
  • 1
Michael
  • 7,348
  • 10
  • 49
  • 86
  • SOLVED: Your update was correct. By adding ... to the /Tomcat 5.5/conf/context.xml file instead of inside the webapp itself it has solved the jar locking issue. Here is your 50 reputation and a very grateful thank you. – PseudoNinja Jun 16 '11 at 15:06
1

I guess your requirement is to deploy and rebuild quickly given eclipse is ur IDE. As you have figured out exporting war file to webapps folder is not the best option. Few other options are

a) Use sysdeo tomcat plugin -- sysdeo deploys the project folder

b) Update build script to deploy in exploded format. -- deploy the \build folder as exploded application

First option is easiest. Second option is cleaner.

[OFF TOPIC] consider switching to tomcat 7

kiran.kumar M
  • 811
  • 8
  • 25
  • We are in the process of migrating to 7 however we have to support a large application that isn't playing well (yet) with Tomcat7. I will look into the sysdeo plugin. – PseudoNinja Jun 16 '11 at 15:00
1

Could this thread be of relevance? Cites the DTD in the tiles-config.xml causing issues.

MJB
  • 9,352
  • 6
  • 34
  • 49
  • "When URL.openAsStream (or some such method, I forget the exact details) is used to load a resource, then the sun jdk caches a reference to that resource in order to optimise future accesses to it. But that means that on Windows the file is "open" so cannot be removed." Interesting, lets see if this issue applies to the asker / OP. – Michael Jun 15 '11 at 14:37
  • Not applicable, we are not using a tiles-config.xml – PseudoNinja Jun 16 '11 at 13:33
0

This is probably not the optimal solution but I have had similar issues with Tomcat 6 before now. At the time I was using Ant, so I wrote an Ant script which would deploy to Tomcat locally and in the process it would stop / start Tomcat where necessary (Tomcat was deployed as a service so I could use NET STOP / NET START commands). This included deleting the old expanded WAR folder.

I think there probably are better options, but this worked for me.