ne-parent是父模块
ne-commo是公共组件模块
ne-web是项目入口模块
错误:
ne-web模块打包的时候,找不到ne-commo公共组件模块的包,找不到ne-commo公共组件模块的类,
原因:
1、ne-commo不能添加spring-boot-maven-plugin插件,如果添加了spring-boot-maven-plugin,当运行maven的package打包命令时,这个SpringBoot插件会在Maven的package后进行二次打包,目的为了生成可执行jar包;
2、二次打包后其他模块引用ne-commo模块就会报错找不到xxx包,找不到xxx类错误
ne-commo子模块的pom.xml中build内容如下:
<modelVersion>4.0.0</modelVersion>
<groupId>com.upincar.ne.commo</groupId>
<artifactId>ne-commo</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>com.upincar.ne.parent</groupId>
<artifactId>ne-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<build>
<plugins>
<!-- 资源文件拷贝插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
ne-parent父模块的pom.xml中bulid内容如下:
<modelVersion>4.0.0</modelVersion>
<groupId>com.upincar.ne.parent</groupId>
<artifactId>ne-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
</parent>
<modules>
<module>ne-commo</module>
<module>ne-web</module>
</modules>
<build>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- java编译插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<compilerArguments>
<verbose/>
<bootclasspath>${java.home}\lib\rt.jar;${java.home}\lib\jce.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
ne-web子模块的pom.xml配置如下:
<modelVersion>4.0.0</modelVersion>
<groupId>com.upincar.ne.web</groupId>
<artifactId>ne-web</artifactId>
<packaging>war</packaging>
<parent>
<groupId>com.upincar.ne.parent</groupId>
<artifactId>ne-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<build>
<finalName>ne-web</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>**/*.woff</exclude>
<exclude>**/*.woff2</exclude>
<exclude>**/*.ttf</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>**/*.woff</include>
<include>**/*.woff2</include>
<include>**/*.ttf</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- 指定该Main Class为全局的唯一入口 ############ -->
<configuration>
<mainClass>com.upincar.xigua.XiguaApplication</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
注:进行如上配置之后,要发布的子模块打war包时,先打包公共模块,再打包要发布的子模块,打包要发布的子模块时就不会报找不到xxx包,找不到xxx类的错误了