Tomcat mapping context via server.xml
Solution 1
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
Solution 2
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>
Admin
Updated on December 13, 2020Comments
-
Admin over 3 years
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?
-
Admin about 12 yearsIf you put the context settings in $CATALINA_HOME/conf/localhost/blah.xml, it deletes the configuration on each app redeploy. Unless there is a way to disable this behavior, whatever benefits you gain by keeping configuration out of server.xml are outweighed by the need to replace the xml configs manually each time.
-
Michael-O about 12 yearsThis is intended behavior and is correct. Since the file is associated with a context it has to be deleted with a redeploy.