Random Tomcat Annoyance

April 1, 2005 11:20 AM

Every tomcat host configuration has a "webapps" directory. By default, web applications dumped into this directory are automatically deployed. So if you put an application into webapps/foo, it will be deployed as http://www.example.com/foo

Simple enough so far.

Tomcat host configurations also allow you to specify web applications explicitly using Context declarations. You add a Context tag, point the docBase parameter at the root of your web application, and voila.

This is where the fun begins.

  • By default, docBase is relative to the webapps directory
  • If something is in webapps and specified in a Context, it is deployed twice: once for the automatic deployment and once for the manual.

It's a subtle useability issue. Every default behaviour or configuration tells the user "this is how the application expects to be used". So if you default to auto-deploying anything placed in a certain directory, and you default to looking for manually deployed applications in the same directory, you're creating an affordance for a broken configuration.

The fact that the fix is dead simple (deploy the app elsewhere, or turn off auto-deployment), and it's a documented problem doesn't make it any less of a bad design decision.

5 Comments

Funny, I just pointed this out to folks on my project today. This is the second time this particular bug has bitten me in the last, oh, 6 months or so. I wish Tomcat would either:
a) be smart and only deploy it once
b) log something!

The only way to notice it is by examining your logs carefuly. I've also seen bad things happen with Hibernate sessions having to do with binding a session to a ThreadLocal variable.

Yea, this bugs the heck out of me. Try resin :)

CP

I am having a similar issue. If I remove the Context tag from the Host tag in the server.xml and place it in J:\Apache Software Foundation\Tomcat 5.5\conf\Catalina\localhost\.xml, the path is not recognized. If I add the Context tag to the server.xml and keep it in the Context app xml file, the path is recognized, but the app is deployed twice. The path only seems to be recognized in the server.xml Any thoughts..

1) Configuration information should behave consistently. The fact that it does not in Tomcat is a major source of confusion not to mention frustration and wasted time.

2) The developers are trying to be too clever by far. Half the time it is necessary to completely reload a Tomcat instance when a web app changes because of loaded static classes, shared classes etc etc. that are not purged during a reload or auto-deployment. Far better to eliminate auto-deployment altogether and just get people to think.

I'm having this problem but how do you get around it?

I'm using the Context tag to try and allow people to connect to my server through a normal 'nested URL' (holidays/myPics/la. But I get two initialisations!

Any ideas?

I am having a problem but I am not sure that it is due to Tomcat bugginess. I am using realms, and permissions through Tomcat, but here is the problem: when I reload the context using the tomcat manager, all current sessions are automatically logged off. This is problematic for obvious reasons... i.e. Deploy new code, reload, clients are logged off. Any suggests please?

Comments are no longer being accepted for this blog entry. If you really want to make your voice heard, you can always email me.

Previously: Memory Management

Next: Programming Metaphors