版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/limm33/article/details/70159711
一、前提
在原有的web项目基础上拆分出了多个web项目,后台代码还是在各个web模块中,现在的需求是要合并多个web模块整合到一个war中部署。
二、配置建议
新建打包的web模块用以合并多个web模块项目,在pom中声明合并打包的各个模块,例如要合并A模块和B模块,如下:
<dependencies>
<dependency>
<groupId>com.inspur.test</groupId>
<artifactId>A</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.inspur.test</groupId>
<artifactId>A</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.inspur.test</groupId>
<artifactId>B</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.inspur.test</groupId>
<artifactId>B</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>pom</type>
</dependency>
</dependencies>
我们需要在合并打包的项目中依赖要合并的各个war包和各个模块的pom。
排除各个模块的lib:
排除各个模块的lib
<build>
<finalName>B</finalName>
<plugins> <!-- 合并多个war -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<overlays> <!-- 声明合并war -->
<overlay>
<groupId>com.inspur.test</groupId>
<artifactId>A</artifactId>
<excludes><!-- 声明排除war包中的部分 -->
<exclude>WEB-INF/lib/*</exclude>
</excludes>
</overlay>
</overlays>
<overlays> <!-- 声明合并war -->
<overlay>
<groupId>com.inspur.test</groupId>
<artifactId>B</artifactId>
<excludes><!-- 声明排除war包中的部分 -->
<exclude>WEB-INF/lib/*</exclude>
</excludes>
</overlay>
</overlays>
</configuration>
</plugin>
</plugins>
</build>