【问题标题】:Run two maven modules using mvn tomcat7:run使用 mvn tomcat7:run 运行两个 maven 模块
【发布时间】:2015-06-27 15:26:54
【问题描述】:

我有以下项目布局:

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

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

出于未知的原因,有人相当武断地拆分了这些项目。我一直在尝试将这些项目合并到一个 Maven 超级项目下。

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

我怎样才能让mvn tomcat7:run 进行两场战争?


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

【问题讨论】:

标签: maven tomcat


【解决方案1】:

从一个虚拟模块运行战争,将所有依赖项列为“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/),这样您也可以在一个操作中将它们部署到生产环境中。

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

【讨论】:

  • 所以对于n webapps 我需要一个n-deep maven 依赖图?好像有点浪费。这回答了“可能重复”的问题,但没有显示我如何在带有子模块的项目中做到这一点......
  • 为什么会有多个war子模块?你在重新发明 EAR 吗?为什么不能与多个控制器/servlet 进行一场战争?
  • 我没有做这些项目,做的人把它弄得一团糟。但是我不想重构太多,因为这会使合并请求相当烦人。
  • 还有什么是EAR?
  • EAR 与 JavaEE Enterprise Archive 一样:docs.oracle.com/javaee/6/tutorial/doc/bnaby.html。但是,您不能使用 tomcat7 运行它们。那么你可以尝试使用 mvn jboss-as:run 代替。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-09
  • 1970-01-01
  • 2013-11-23
  • 1970-01-01
  • 2010-12-13
相关资源
最近更新 更多