springboot项目打成jar包运行时提示文件不能找到。如下这样的提示
Failed to parse configuration class [xxx]; nested exception is java.io.FileNotFoundException: class path resource [xxx] cannot be opened because it does not exist
查找了很多方法,如路径不对的,配置文件未被打包的都没有解决问题。
详细研究日志偶尔发现找不到的文件在另一个模块中,研究后发现是打包配置写错了,导致多模块中的其他模块没有被打入包中。
正确的多模块打包方法如下:
1)在启动类模块中的pom.xml配置org.springframework.boot插件。
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.3.RELEASE</version>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
2)原理
在多模块下,直接使用maven进行选择父模块进行打包,会出现子模块分别进行打包,而父模块未打包的情况,这是正常的,因为父模块打包方式是pom,子模块打包方式是jar,所以不会出现父模块的打包。
我们想实现运行一个jar包就可以运行整个项目时,我们要在springboot启动类所在模块的pom文件中,添加一段管理maven打包的代码。

2510

被折叠的 条评论
为什么被折叠?



