jQuery in Action, 2nd edition*
The moose likes Tomcat and the fly likes Configuring a context outside of $CATALINA_HOME/webapps Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Configuring a context outside of $CATALINA_HOME/webapps" Watch "Configuring a context outside of $CATALINA_HOME/webapps" New topic

Configuring a context outside of $CATALINA_HOME/webapps

deb platt
Ranch Hand

Joined: Jan 23, 2008
Posts: 44
Originally posted by Ben Souther at why .war file in webapps folder only...:
The webapps directory is the the default place to put web apps but it's far from the only place you can put them....You can configure the docbase to point to any directory on your system that Tomcat can see.

For more details, see:

I am apparently having some difficulties following the above documentation. Here's what I'm trying to do on my windows machine. For the most part, I want tomcat to behave in the default way, serving up contexts under the webapps directory. However, I'd also like to serve up documents in one directory outside of webapps. So to do a test run of this, I created a file, "C:\testcontext\index.html". On the same machine, I attempted to create a context description, named "testcontext.xml". Here are it's contents:

Next I had to decide where to put it. Since I only wanted one context to behave in a non-default way, the documentation seemed to suggest that there was only one place for me to put the xml file:
$CATALINA_HOME/conf/[enginename]/[hostname]/ . So I interpreted this as meaning I should put testcontext.xml in $CATALINA_HOME/conf/Catalina/localhost/. I stopped and restarted Tomcat. I then entered the URL for the default webapp (http://localhost:8080) -- that worked fine. Next I tried entering the URL testcontext (http://localhost:8080/testcontext/index.html). That resulted in a 404. I went and checked the catalina log and it said:
SEVERE: Error starting static Resources
java.lang.IllegalArgumentException: Document base C:\Apps\Tomcat_6.0\webapps\testcontext does not exist or is not a readable directory ... INFO: Container org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/testcontext] has not been started

At this point I'm looking around some more and I run into documentation that says for me to not set the path attribute, as this will be inferred. So I remove that from testcontext.xml, so it's contents are now:

However I still get a 404 and the log still reports the same error.

I then wonder if the direction of the slash makes a difference, and I change the value of docBase to be "/testcontext" with the same results.

I'm apparently misunderstanding the documentation. Any guidance would be appreciated.

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Three things.
Does your testcontext directory have a WEB-INF directory inside it?
If not, add it (spelling is case sensitive so be sure to type in in all upper case).

Try fully qualifying the docBase attribute.

Where are you putting testcontext.xml?
[ June 23, 2008: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
deb platt
Ranch Hand

Joined: Jan 23, 2008
Posts: 44
First to answer your question, testcontext.xml is located in $CATALINA_HOME/conf/Catalina/localhost/. The expanded path on my machine is C:\Apps\Tomcat_6.0\conf\Catalina\localhost\testcontext.xml

Previously my entire context was one directory (/testcontext) holding one file (index.html). After reading your post, I created the subdirectory /textcontext/WEB-INF. When I restarted tomcat, the catalina log reported the same errors and I got a 404 when I attempted to access index.html via my browser.

Next I tried changing the contents of testcontext.xml to be the following: <Context docBase="C:\testcontext" /> When I restarted tomcat, I was delighted that no errors were reported in the catalina log. When I attempted to access index.html via the URL http://localhost:8080/testcontext/index.html the page appeared in my browser as I had hoped.

I thank you for your help! I had wanted to try doing this on my laptop before trying it on our Solaris server. For a UNIX-like OS, I am assuming that that I would change textcontext.xml as follows: <Context docBase="/testcontext" />

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

That's how I do it on my Linux workstation.
It is sorta covered in the JavaRanch Style Guide.
subject: Configuring a context outside of $CATALINA_HOME/webapps
Similar Threads
Running project outside Tomcat webapp folder
problem in context root
why .war file in webapps folder only
Problem deploying WAR file with a context.xml
Eclipse Integrated with Tomcat for Hot Deployment