异常描述:springboot项目进行 mvn install时 报错如下
Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.2.7.RELEASE:repackage (repackage) on project match-service: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.2.7.RELEASE:repackage failed: Unable to find main class
排查报错原因:
在各模块的pom.xml中均引入了maven 打包插件
<build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build>
在插件运行时
需要指定或者继承了spring-boot-starter-parent并且配置需属性,然后插件会自动寻找签名是public static void main(String[] args)的方法… ,
mainClass和statrt-class即程序的入口,即使用了@SpringBootApplication注解且有main方法的启动类,
我这里的原因是,由于没有添加启动类。所以执行mvn install时会报上述异常
解决办法:
添加启动类或者注释掉没有启动类的模块pom中的上述依赖。
附加知识点:
下配置mainClass,指定程序入口。
<plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><version>1.5.3.RELEASE</version><configuration><mainClass>com.xx.webapps.api.main.WebappsApiBidMain</mainClass></configuration><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin>
Spring Boot Maven Plugin提供了几个目标(goal),我们在标签里配置的repackage对应spring-boot:repackage这个目标。
如果你的pom继承自spring-boot-starter-parent(注意此前提),也可以直接在配置(其实这里的start-class直接对应清单文件里的Start-Class):
<properties><start-class>com.xx.webapps.api.main.WebappsApiBidMain</start-class></properties>