How can I configure Tomcat 7 to allow a WAR file to specify its own context root, which is NOT based on the WAR file name? Example: I have A-1.0.0.war and B-1.0.0.war and I want to deploy both to the same Tomcat instance. When the deployment finishes, I want to point browser to localhost:8080/portal and see the contents in A-1.0.0.war, and I want to curl a rest request to localhost:8080/rest/v1/helloworld whose implementation comes from B-1.0.0.war.
I have scouted around and tried configuring different ways, but none of these are producing my desired scenario above. Also, I find the Tomcat documentation a bit too sparse to understand fully. I've read:
After digesting those, in %CATALINA_HOME%/conf/server.xml I have this single Host entry:
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
deployXML="true" copyXML="true" >
<Context path="/portal" docBase="/www/" reloadable="true" swallowOutput="true">
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Logger className="org.apache.catalina.logger.FileLogger" prefix="www-sample-com-log." suffix=".txt" timestamp="true"/>
</Context>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
This is the full content of A.war/META-INF/context.xml from one of the WAR files:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/portal" docBase="ROOT/portal" />
When I deploy to Tomcat via the Admin console, I am using the "WAR file to deploy" buttons, but I am not specifying any of the fields under the "Deploy directory or WAR file located on server" (because I want these to come from the WAR itself, not make someone specify it). When I open the webapps directory, I see this listing. I would expect to see, instead of A-1.0.0/
directory, portal/
:
A-1.0.0/
B-1.0.0/
docs/
examples/
host-manager/
manager/
ROOT/
sample/
A-1.0.0.war
B-1.0.0.war
sample.war
In case it helps, here's some backstory to my scenario. My objective is to move an application bundled in a single .jar into two .war files. Currently, it's a maven project that produces a single jar as its build artifact containing both a Spring MVC and a JSP application. My client is starting up the application on command line using java. Where I want to get to is standing up a Tomcat 7 install on our dev server, which someone can deploy a WAR file through Tomcat's admin console. I also want to put a version number in the file name of the WAR so that it's clear to the people handling the WAR what they are deploying. On every build/release cycle, I want them to un-deploy the old war and deploy the new war. As a side note - this is the first time I'm attempting to deploy an application as a war, and I may have missed some best practice on doing this, so do kindly correct me if this is not a good way.