This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Configuring a context outside of $CATALINA_HOME/webapps

 
deb platt
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
http://tomcat.apache.org/tomcat-6.0-doc/config/index.html


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.

Deb
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
docBase="c:\testcontext".

Where are you putting testcontext.xml?
[ June 23, 2008: Message edited by: Ben Souther ]
 
deb platt
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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" />

Deb
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.
That's how I do it on my Linux workstation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic