使用mvn tomcat7:run运行两个maven模块

时间:2015-04-20 18:35:59

标签: maven tomcat

我有以下项目布局:

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

我的web_root pom.xml项是超级项目,包含两个modulesweb_relayweb_service

由于不明原因,有人会擅自拆分这些项目。我一直在尝试将这些项目合并到一个maven超级项目下。

我可以使用web_relay运行每个web_servicemvn tomcat7:run项目。但是,我需要在同一个tomcat服务器上运行。但是,当我在tomcat7:run上运行web_root时,它只为两个模块中的一个运行tomcat服务器。

如何让mvn tomcat7:run同时进行两场战争?


来自How to use maven plugin tomcat7:run with multiple contexts (WARs)?的方法仅在我mvn install我的依赖关系单独且不包含modules时才有效。如果我将它们包含为modules,则mvn将在它找到的第一个模块中运行tomcat7:run

1 个答案:

答案 0 :(得分:0)

从虚拟模块运行war,将所有依赖项列为' webapps'。

即。在个人pom中,使用:

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

创建一个新模块,立即启动所有依赖项

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

作为替代方案,从长远来看可能是更好的解决方案,将所有Web应用程序打包在一个EAR(企业归档文件:https://maven.apache.org/plugins/maven-ear-plugin/)中,这样您也可以在一个操作中将它们部署到生产环境中。 / p>

Tomcat7不支持EAR部署,但TomEE执行:http://tomee.apache.org/maven/run-mojo.html 还有JBoss:https://docs.jboss.org/jbossas/7/plugins/maven/latest/run-mojo.html

相关问题