How can I point the “Context Path” to Tomcat 8 inside META-INF / context.xml in the java war file?

How can I deploy mywebapp-1.0.0.war to the $ TOMCAT_HOME / webapps directory with the / mywebapp context path using context.xml inside the war file on Tomcat 8?

I get back to work with Tomcat after a long time, starting with version 5. I am used to creating META-INF / context.xml inside my war file:

<?xml version="1.0" encoding="UTF-8"?> <Context path="/mywebapp"> ... </Context> 

Maven creates a war file with this name: mywebapp-1.0.0.war

But when I deploy the war file in the $ TOMCAT_HOME / webapps directory, the context path will look like http: // localhost: 8080 / mywebapp-1.0.0 instead of http: // localhost: 8080 / mywebapp / .

I also see that $ TOMCAT_HOME / conf / Catalina / localhost is empty, instead of copying the xml file from the deployed war file.

I also added the deployXML = "true" file to $ TOMCAT_HOME / conf / server.xml

  <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" deployXML="true"> 
+5
source share
3 answers

It is not possible to wage war in the webapp directory and set the path attribute in the META-INF / context.xml file at the same time. Tomcat 8 documentation clearly talks about this attribute:

This attribute should only be used with a static Context definition in server.xml. In all other cases, the path will be inferred from the file names used for the .xml or docBase context file.

+8
source

Can't you just rename your war file to mywebapp (via Maven or else) so that Tomcat will deploy it under / mywebapp?

+1
source

Thanks for your research on j2gl! I found out that a good way to get both .war files with the full name with the version, and the deployed shortcut is to use the Tomcat API. For example, through Tomcat7-maven-plugin.

-1
source

All Articles