一,对于父模块:
打war包时,父模块的pom无需啥特殊处理[可以去掉 spring-boot-starter-web 中自带的tomcat]
打jar包时,启用注释掉的板块,然后内嵌的tomcat不能去掉。
<!-- 父模块包含的子模块要在父模块中注册 -->
<modules>
<module>parent-web</module>
<module>platform-config</module>
<module>panorama-bulletin</module>
<module>operational-monitoring</module>
<module>diagnostic-analysis</module>
<module>warning-sheet-center</module>
<module>data-report</module>
<module>link-common</module>
</modules>
<!-- 注意父包的打包方式为pom -->
<packaging>pom</packaging>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!-- 移除嵌入式tomcat插件 -->
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--添加servlet的依赖 POM(去除内嵌tomcat后,需要添加servlet依赖) -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- 打jar包时使用,war时注释掉 -->
<!--默认关掉单元测试 -->
<!--
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
-->
二、总的web模块:
所有的子模块都要被依赖到,
打war包时,注意在每个子模块依赖上加上<type>war</type>
但是打jar时,不要<type>war</type>这句。
<dependency>
<groupId>com.xxx.energy.solar</groupId>
<artifactId>platform-config</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.xxx.energy.solar</groupId>
<artifactId>data-report</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.xxx.energy.solar</groupId>
<artifactId>diagnostic-analysis</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.xxx.energy.solar</groupId>
<artifactId>operational-monitoring</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.xxx.energy.solar</groupId>
<artifactId>panorama-bulletin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.xxx.energy.solar</groupId>
<artifactId>warning-sheet-center</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
<build>
<finalName>parent-web</finalName>
<plugins>
<!-- 打war包时使用,jar时注释掉 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<overlays>
<overlay>
<groupId>com.xxx.energy.solar</groupId>
<artifactId>platform-config</artifactId>
</overlay>
<overlay>
<groupId>com.xxx.energy.solar</groupId>
<artifactId>data-report</artifactId>
</overlay>
<overlay>
<groupId>com.xxx.energy.solar</groupId>
<artifactId>diagnostic-analysis</artifactId>
</overlay>
<overlay>
<groupId>com.xxx.energy.solar</groupId>
<artifactId>operational-monitoring</artifactId>
</overlay>
<overlay>
<groupId>com.xxx.energy.solar</groupId>
<artifactId>panorama-bulletin</artifactId>
</overlay>
<overlay>
<groupId>com.xxx.energy.solar</groupId>
<artifactId>warning-sheet-center</artifactId>
</overlay>
</overlays>
</configuration>
</plugin>
<!-- 打jar包时使用,war时注释掉 -->
<!-- 指定该Main Class为全局的唯一入口 -->
<!--可以把依赖的包都打包到生成的Jar包中-->
<!-- <plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
<mainClass>com.xxx.energy.solar.LinkEnergySolarApplication</mainClass>
<layout>ZIP</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>-->
</plugins>
</build>
三、子模块
罗列一个子模块例子
当子模块不依赖其它子模块时,打war包
<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <fork>true</fork> </configuration> </plugin>
当子模块有依赖其它子模块时,不用加这句,在其依赖的子模块上加就行。
打jar包时,启用注释掉的语句块。需要注意的时,当子模块也有主函数的,即子模块是可以独立的运行的模块时,也需要注明主函数的入口。如果没有可以忽略。
<build>
<plugins>
<!-- 打war包时使用,jar时注释掉 -->
<!-- 如果该模块有子模块依赖,则这一语句块也不用加,啥也不写就行 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
<!-- 打jar包时使用,war时注释掉 -->
<!-- 指定该Main Class为全局的唯一入口 -->
<!--可以把依赖的包都打包到生成的Jar包中-->
<!--<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
<mainClass>com.xxx.energy.solar.PlatformConfigApplication</mainClass>
<layout>ZIP</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>-->
</plugins>
</build>
另:
打war包时,所有有主类的pom.xml
<packaging>war</packaging>
打jar包时,所有有主类的pom.xml
<packaging>jar</packaging>