1

I've got the following project layout:

web_root
- pom.xml -> packaging: pom
- web_relay
     - pom.xml -> packaging: war
     - src/...
- web_service
     - pom.xml -> packaging: war
     - src/...

My web_root's pom.xml has is the superproject and contains two modules: web_relay and web_service.

For reasons unknown someone split these projects rather arbitrarily. I've been trying to merge these projects under one maven superproject.

I can run each of the web_relay and web_service projects using mvn tomcat7:run. However, I need both running on the same tomcat server. When I run tomcat7:run on web_root, however, it only runs the tomcat server for one of the two modules.

How can I get mvn tomcat7:run to run both wars?


The approach from How to use maven plugin tomcat7:run with multiple contexts (WARs)? works only if I mvn install my dependencies separately and don't include them as modules. If I do include them as modules, mvn will just run tomcat7:run in the first module it finds.

Community
  • 1
  • 1
Thom Wiggers
  • 6,938
  • 1
  • 39
  • 65

1 Answers1

0

Run the war's from a dummy module, listing all dependencies as 'webapps'.

I.e. in the individual pom's, use:

<build>
     <plugins>
         <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <configuration>
                    <skip>true</skip>

And make a new module that launches all dependencies at once

<build>
     <plugins>
         <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <configuration>
                    <webapps>
                       <webapp> 
                         <groupId>com.company</groupId> 
                         <artifactId>webapp-1</artifactId> 
                         <version>1.0</version> 
                         <type>war</type>    
                       </webapp> 
                       [Add more]
                    </webapps>

As an alternative, and maybe a better solution in the long run, package all web applications in a single EAR (enterprise archive: https://maven.apache.org/plugins/maven-ear-plugin/), so you can also deploy them in production in a single action.

Tomcat7 does not support EAR deploys, but TomEE does: http://tomee.apache.org/maven/run-mojo.html And JBoss, too: https://docs.jboss.org/jbossas/7/plugins/maven/latest/run-mojo.html

GeertPt
  • 16,398
  • 2
  • 37
  • 61
  • So for `n` webapps I need an `n`-deep maven dependency graph? Seems like a bit of a waste. This answers the 'possible duplicate' question, but doesn't show how I can do this in a project with submodules... – Thom Wiggers Apr 21 '15 at 16:28
  • Why do you have multiple war submodules? Are you re-inventing the EAR? Why can't you make a single war with multiple controllers/servlets? – GeertPt Apr 28 '15 at 11:37
  • I didn't make the projects, and the person who did kind of made a mess of it. However I don't want to refactor too much because that would make merge requests rather annoying. – Thom Wiggers Apr 29 '15 at 12:42
  • Also what is the EAR? – Thom Wiggers Apr 29 '15 at 12:43
  • EAR as in JavaEE Enterprise Archive: http://docs.oracle.com/javaee/6/tutorial/doc/bnaby.html. You can't run them with tomcat7, though. You could try with mvn jboss-as:run instead, then. – GeertPt May 06 '15 at 13:01