Nelz' Blog

Ruminations on Development


« Burn My Brain | Main | Participation Cultur... »
Sunday May 11, 2008

Tomcat ROOT Context

I've been fighting with Tomcat a bunch this week.

My specific challenges have been around configuring a webapp to have the context root of "/", without having to name it ROOT.war...

The documentation page on context configuration says that "Context elements may be explicitly defined":

  • in the $CATALINA_HOME/conf/context.xml file- the Context element information will be loaded by all webapps
  • in the $CATALINA_HOME/conf/[enginename]/[hostname]/context.xml.default file- the Context element information will be loaded by all webapps of that host
  • in individual files (with a .xml extension) in the $CATALINA_HOME/conf/[enginename]/[hostname]/ directory. The name of the file (less the .xml) extension will be used as the context path. Multi-level context paths may be defined using #, e.g. context#path.xml. The default web application may be defined by using a file called ROOT.xml.
  • if the previous file was not found for this application, in an individual file at /META-INF/context.xml inside the application files
  • inside a Host element in the main conf/server.xml

In my experience this week, the option of creating the file $CATALINA_HOME/conf/[enginename]/[hostname]/ROOT.xml didn't work for me.

But, one of my coworkers (Chris) found some other resource somewhere that said you could create a $CATALINA_HOME/webapps/ROOT.xml that looked like this:

<?xml version='1.0' encoding='utf-8'?>
<Context docBase="/absolute/path/to/your/webapp/dir">
</Context>

Chris tried this setup, and it seemed to work for him. Here's my caveats:

  1. I haven't verified this myself yet.
  2. I'm not sure if it has to be an exploded WAR file structure, or if it can be a WAR file itself.

I will update if I find that this actually does work.

Comments:

Did you find a solution to your problem in the end?

I think I'm having a similar issue!

Posted by JonB on July 28, 2008 at 07:51 AM PDT #

Hey Jon,

From what I can tell, the $CATALINA_HOME/webapps/ROOT.xml thing doesn't work.

We just ended up making an ANT task (or three) that renames the artifact to ROOT.war when it gets copied to the $CATALINA_HOME/webapps/ directory.

Yeah, it's very frustrating... :-(

Posted by Nelz on July 28, 2008 at 10:57 AM PDT #

I ended up renaming the web app file to ROOT.war too as I couldn't get any other way to work properly and I didn't want to define it in server.xml as it meant a restart of Tomcat every time I wanted to change the context.

Not ideal really but does the job!

Posted by JonB on August 03, 2008 at 02:16 PM PDT #

Post a Comment:
  • HTML Syntax: Allowed