Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 872
static-fading Avatar asked Feb 24 '12 17:02

static-fading


People also ask

Where do I put the context path in server xml?

xml. The second option is to set the context path of the application in the server. xml (which is located at $CATALINA_HOME\conf). Note: defining the context path manually has the side effect that the application is deployed twice by default: at http://localhost:8080/ExampleApp/ as well as at http://localhost:8080/.

Where is Tomcat context xml?

context. xml file is the application deployment descriptor for the Apache Tomcat server. In a deployed application, this file is located in the META-INF folder of the web application directory or the WAR file, for example, tomcat/webapps/app-core/META-INF/context. xml .

What is the use of server xml in Tomcat?

The server. xml file is Tomcat's main configuration file, and is responsible for specifying Tomcat's initial configuration on startup as well as defining the way and order in which Tomcat boots and builds. The elements of the server.


1 Answers

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

like image 120
Jacky Avatar answered Oct 13 '22 01:10

Jacky