300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > jenkins用spring-boot-maven-plugin构建出错:repackage failed: Unable to find main class

jenkins用spring-boot-maven-plugin构建出错:repackage failed: Unable to find main class

时间:2023-11-03 17:15:17

相关推荐

jenkins用spring-boot-maven-plugin构建出错:repackage failed: Unable to find main class

完整的报错信息如下:

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.4.RELEASE:repackage (default) on project mfsms-updatereceipt: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:2.0.4.RELEASE:repackage failed: Unable to find main class -> [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] /confluence/display/MAVEN/PluginExecutionException

[ERROR]

[ERROR] After correcting the problems, you can resume the build with the command

[ERROR] mvn -rf :mfsms-updatereceipt

主要是Unable to find main class,找不到主类,也就是启动类

首先是我根据问题查询来的答案:

/thinking-better/p/7827368.html

可以通过在pom.xml中指定mainclass来使得构建成功

<plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><mainClass>com.xx.MyappApplication</mainClass></configuration></plugin>

说是多个@SpringBootApplication注解会导致主类冲突,或者在没有该启动类注解的情况下有多个public static void main。我并没有这种情况,在指定mainclass后可以成功构建,但是生成的jar包无法执行,显示

Exception in thread “main” java.lang.ClassNotFoundException: com.xx.MyappApplication

于是又鼓捣半天后也还是不能成功打包+执行

后面仔细查看jenkins的报错

[INFO] — maven-resources-plugin:3.0.2:resources (default-resources) @ mfsms-updatereceipt —

[INFO] Using ‘UTF-8’ encoding to copy filtered resources.

[INFO] skip non existing resourceDirectory /root/.jenkins/workspace/MFSMS-updatereceipt/mfsms-updatereceipt/src/main/resources

[INFO] skip non existing resourceDirectory /root/.jenkins/workspace/MFSMS-updatereceipt/mfsms-updatereceipt/src/main/resources

[INFO]

[INFO] — maven-compiler-plugin:3.7.0:compile (default-compile) @ mfsms-updatereceipt —

[INFO] No sources to compile

[INFO]

这里显示compile编译下找不到东西,resouce也找不到

后面仔细对比路径后发现 src/main写成了src/mian

看来spring-boot-maven插件构建时默认找的是pom.xml所在路径下的src/main文件夹,名字拼错和类似web/src/main的嵌套文件夹都会出现这样的错误。当然也可以在pom文件里指定路径来解决。

因此如果你也出现了和我一样的问题,百度其他方法无效,不妨先

检查一下启动类src/main的路径是否填写正确,是否不存在嵌套文件夹的情况

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。