0

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
ywy
  • 69
  • 1
  • 4

2 Answers2

0

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"/>
Ravi
  • 30,829
  • 42
  • 119
  • 173
  • Is it the context.xml under xx.war/META-INF ? – ywy Mar 29 '17 at 09:22
  • yes correct. same context.xml. Also, I would suggest you to completely un-deploy your existing application before deploying the new one – Ravi Mar 29 '17 at 09:24
  • sorry I've tried this do not work either... the webapps/app-payment.war still becomes localhost:8080/app-payment... find this [link](http://stackoverflow.com/questions/7276989/howto-set-the-context-path-of-a-web-application-in-tomcat-7-0) though... – ywy Mar 29 '17 at 09:45
  • did you deleted old deployment completely ? – Ravi Mar 29 '17 at 09:46
  • You are not tweaking tomcat. You are modifying your application – Ravi Mar 29 '17 at 09:47
  • Tell me, when you tried my solution what just happened ?? You need to clean your previously deployment. If possible restart your tomcat after undeployment – Ravi Mar 29 '17 at 09:52
  • http://stackoverflow.com/questions/9522054/changing-tomcat-context-path-of-web-project-in-eclipse similar post – Ravi Mar 29 '17 at 09:53
  • Thanks. I pasted the log. I packed a new payment.war with its META-INF/context.xml has `` and put to webapps/ (no api.war this time). Before that there were only default tomcat apps left and tomcat was stopped (so it was restarted). – ywy Mar 29 '17 at 10:10
  • sorry I just discover that using the default /Manager page (_Deploy directory or WAR file located on server_ form) tomcat will create api#payment.war and api#payment (folder) under webapps/ and then /api/payment url could be reached. I'll make do for the moment and read the docs... thanks very much for the help. – ywy Mar 29 '17 at 10:34
0

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).

SiLeNCeD
  • 240
  • 4
  • 13