0
votes

I have a multi-module maven project whose structure looks like this:

app                // parent/root project folder
 |- src         
 |- target
      |- app.war   // common features
 |- app-payment    // child/module folder
        |- src   
        |- target
             |- app-payment.war  // shop/pay features

How can I map the two war files to urls like below?

requests for    
   localhost:8080/app/payment   --goto-->   $CATALINA_HOME/webapps/app-payment.war (or any other locations, doesn't matter)
other requests for
   localhost:8080/app           --goto-->   $CATALINA_HOME/webapps/app.war

The web.xml -> <servlet-mapping> both are <url-pattern>/</url-pattern>.

I'm using tomcat 8.5 and want to keep default settings if possible (e.g., do not add <Context> in server.xml, leave autoDeploy=true). So probably the approaches provided in A word on Contexts at https://tomcat.apache.org/tomcat-8.5-doc/deployer-howto.html would not work (have tried anyway and no).

In case this turns out to be an XY problem...Is it the right way to use/modify tomcat to achieve such url pattern? Or should I change the project settings (or design)? It's a spring-mvc project and the whole spring-*.xml thing is like a myth...


catalina.2017-03-29.log:

29-Mar-2017 17:28:49.472 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
29-Mar-2017 17:28:49.472 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.5
29-Mar-2017 17:28:49.494 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive C:\Program_Files\tomcat-8.5.5\webapps\payment.war
29-Mar-2017 17:28:49.505 WARNING [localhost-startStop-1] org.apache.catalina.startup.SetContextPropertiesRule.begin [SetContextPropertiesRule]{Context} Setting property 'antiJARLocking' to 'true' did not find a matching property.
29-Mar-2017 17:28:51.071 INFO [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
29-Mar-2017 17:28:52.480 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive C:\Program_Files\tomcat-8.5.5\webapps\payment.war has finished in 2,985 ms
29-Mar-2017 17:28:52.482 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\Program_Files\tomcat-8.5.5\webapps\docs
29-Mar-2017 17:28:52.494 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory C:\Program_Files\tomcat-8.5.5\webapps\docs has finished in 12 ms
29-Mar-2017 17:28:52.494 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\Program_Files\tomcat-8.5.5\webapps\examples
2

2 Answers

0
votes

Try changing context.xml of your war file

 <Context antiJARLocking="true" path="/app/payment"/>

By default, it would be

 <Context antiJARLocking="true" path="/app-payment"/>
0
votes

I know this is an old post, but thought I'd share. I had to do something similar where I have a web application, then another separate web application that needed to run under the core app's same directory name. So something like...

https://www.example.com/webapp (main app)
https://www.example.com/webapp/subapp (sub-app)

To do this, I deployed it to the Tomcat webapps folder like this:

../webapps/webapp.war
../webapps/webapp#subapp.war

Worked like a charm for me. If I remember correctly, this is fully supported without any other configuration (both Tomcat v7 and v8... haven't tried v9 yet).