Error building jenkins with 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] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn -rf :mfsms-updatereceipt

Mainly Unable to find main class, the main class cannot be found, which is the startup class

The first is the answer I have based on the question:

https://www.cnblogs.com/thinking-better/p/7827368.html

You can make the build successful by specifying the mainclass in pom.xml

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

It is said that multiple @SpringBootApplication annotations will cause the main class conflict, or there are multiple public static void main without the startup class annotation. I don’t have this situation. It can be successfully built after specifying the mainclass, but the generated jar package cannot be executed, showing

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

So after a long time of tinkering, I still can’t successfully package + execute.
Then carefully check the error report of 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]

It shows that nothing can be found under compile compilation, and neither can resouce be found
. After careful comparison of the paths, it is found that src/main is written as src/mian.
It seems that when the spring-boot-maven plug-in is built, it is found in the path where pom.xml is located by default . src/main folder , misspelled names and nested folders like web/src/main will cause such errors. Of course, it can also be solved by specifying the path in the pom file.
Therefore, if you have the same problem as me, Baidu’s other methods are invalid.

Check whether the path of the startup class src/main is filled in correctly and whether there is no nested folder

Guess you like

Origin blog.csdn.net/qq_35530005/article/details/109333356