static-fading
static-fading

Reputation: 101

Tomcat mapping context via server.xml

I created a war and deployed it to my $CATALINA_HOME/webapps folder just fine. Then I wanted to test configuring it to point to a war at an arbitrary location such as c:\tmp\mywar.war. Here is what I put in the server.xml file within $CATALINA_HOME/conf.

<Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true">
<Context path="/blah" docBase="h:/tmp/mywar.war" reloadable="true" />
</Host>

Tomcat returns 404 when I try to load localhost:8080/blah. If I point docBase to the exploded war instead, it works just fine. What am I missing here?

Upvotes: 10

Views: 49388

Answers (4)

JoSSte
JoSSte

Reputation: 3372

If you want to have a site available at http://myhost:8080/myTestContext, put the following in $Catalina_home$/conf/localhost/whateveryoulike.xml

<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
    <Context deployOnStartup="true" docBase="C:\path\to\your\docBase\" path="/myTestContext" reloadable="false">
    <Manager pathname=""/>
</Context>

Upvotes: 5

JonnyRaa
JonnyRaa

Reputation: 8038

I just ran into this problem. Slightly embarrassingly it was because I got a path wrong!

You can verify this by checking the logs (standard error ones) under

[Tomcat install directory]/logs

You'll see something that looks like this:

Jun 16, 2014 12:34:10 PM org.apache.catalina.core.StandardContext resourcesStart SEVERE: Error starting static Resources java.lang.IllegalArgumentException: Document base ... does not exist or is not a readable directory

A further note (you won't get an error message for this) is that if you are deploying a war rather than an exploded webapp you have to specify the file's path and not just it's containing directory.

Upvotes: 0

Jacky
Jacky

Reputation: 8935

You'd better put the context configuration in an individual file at /META-INF/context.xml inside the application files.

It is NOT recommended to place elements directly in the server.xml file. This is because it makes modifying the Context configuration more invasive since the main conf/server.xml file cannot be reloaded without restarting Tomcat.

You can check out more details in Tomcat7 document here: http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Defining_a_context

Upvotes: 5

Michael-O
Michael-O

Reputation: 18430

Don't do that, this approach is discouraged from Tomcat 6:

For Tomcat 6, unlike Tomcat 4.x, it is NOT recommended to place elements directly in the server.xml file. This is because it makes modifying the Context configuration more invasive since the main conf/server.xml file cannot be reloaded without restarting Tomcat.

Upvotes: 0

Related Questions