springboot多模組打包報錯,找不到xxx包,找不到xxx類
阿新 • • 發佈:2018-12-17
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類的錯誤了