背景
maven父子工程间引用打包,产生的异常
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.1.12.RELEASE:repackage (repackage) on project shop-common: Execution repackage of goal org.springfr
amework.boot:spring-boot-maven-plugin:2.1.12.RELEASE:repackage failed: Unable to find a single main class from the following candidates [com.huanchuang.common.util.CommonAlgoUtil,
com.huanchuang.common.util.DateUtils, com.huanchuang.common.service.impl.MdSensorServiceImpl] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <args> -rf :shop-common
解决
那如何解决呢
1.父子工程引用
多模块依赖时,如果类似common之类的module只作为依赖包,而无需作为springboot的application时,以下打包插件不应配置到顶级pom及common的pom中
<plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
2.单一工程
在pom.xml文件中加入主类,用于指定加载的主类(用于告诉spring boot maven plugin哪个类是入口类即可)
<plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><mainClass>com.huanchuang.commmon.Application</mainClass></configuration>
</plugin>
PS: 其中在打包的时候resources文件下所有的目录都会自动被打包,如果是没有加载上去,可以按照下面的方式指定静态文件
<resources><resource><directory>src/main</directory><includes><include>**/*.properties</include></includes><filtering>false</filtering></resource>
</resources>