How can I tell e.g. Tomcat to use a specific context path when given my WAR-File?
Example: I have a war file created by maven build and the resulting name of the fil
There are two important points in the the documentation of the Context Container:
- In individual files (with a ".xml" extension) in the
$CATALINA_BASE/conf/[enginename]/[hostname]/directory. The name of the file (less the .xml extension) will be used as the context path. Multi-level context paths may be defined using #, e.g. foo#bar.xml for a context path of /foo/bar. The default web application may be defined by using a file called ROOT.xml.- Only if a context file does not exist for the application in the
$CATALINA_BASE/conf/[enginename]/[hostname]/, in an individual file at/META-INF/context.xmlinside the application files. If the web application is packaged as a WAR then/META-INF/context.xmlwill be copied to$CATALINA_BASE/conf/[enginename]/[hostname]/and renamed to match the application's context path. Once this file exists, it will not be replaced if a new WAR with a newer/META-INF/context.xmlis placed in the host's appBase.
So, when you bundle a META-INF/context.xml, the file gets renamed to the name of the WAR and this name becomes the context path, regardless of any path defined in the Context element.
I see thus two options here:
Either set the name of the generated war to a shorter name (I suggest using over which is deprecated AFAIK):
...
mycontext
...
...
Or use the maven-tomcat-plugin for the deployment and set the context path in the plugin configuration:
...
...
...
org.codehaus.mojo
tomcat-maven-plugin
1.0-SNAPSHOT
/mycontext
...
...
...