SpringBoot——Failed to execute goal org.springframework.boot:spring-boot-maven-plugin

阳光穿透心脏的1/2处 2021-10-25 14:56 561阅读 0赞

一、问题:springboot项目打jar包报错

  1. [ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.1.7.RELEASE:repackage (repackage) on project model: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.1.7.RELEASE:repackage failed: Unable to find main class -> [Help 1]
  2. [ERROR]
  3. [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
  4. [ERROR] Re-run Maven using the -X switch to enable full debug logging.
  5. [ERROR]
  6. [ERROR] For more information about the errors and possible solutions, please read the following articles:
  7. [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
  8. [ERROR]
  9. [ERROR] After correcting the problems, you can resume the build with the command
  10. [ERROR] mvn <goals> -rf :model

二、解决方案一

1、错误原因:

我已经设置了启动类,又在pom中引入了spring-boot-maven-plugin

image.png

image.png

2、解决:

保留启动类,将pom中引入的spring-boot-maven-plugin换成普通的_maven-plugin_
_

3、注意:

此方案是我在其他博客上看到的,确实能解决打包不成功问题,但是打包可能成功了,但是运行jar包时,会报另外一个错“xxx.war中没有注清单属性”,还是需要引入spring-boot-maven-plugin,怎么办呢?请见方案二

三、解决方案二

1、在根pom文件中加入:

  1. <pluginRepositories>
  2. <pluginRepository>
  3. <id>spring-snapshots</id>
  4. <url>https://repo.spring.io/snapshot</url>
  5. </pluginRepository>
  6. <pluginRepository>
  7. <id>spring-milestones</id>
  8. <url>https://repo.spring.io/milestone</url>
  9. </pluginRepository>
  10. </pluginRepositories>

2、将根pom文件中的spring-boot-maven-plugin移到web层

  1. <build>
  2. <plugins>
  3. <plugin>
  4. <groupId>org.springframework.boot</groupId>
  5. <artifactId>spring-boot-maven-plugin</artifactId>
  6. <configuration>
  7. <mainClass>com.whm.SpringbootTestApplication</mainClass>
  8. </configuration>
  9. </plugin>
  10. </plugins>
  11. </build>

四、启动方式

1、jar启动

  1. java -jar web-0.0.1-SNAPSHOT.jar

2、war启动

先打war包,没有web.xml的项目如何打war包呢?

  1. <packaging>war</packaging>
  2. <build>
  3. <plugins>
  4. <plugin>
  5. <artifactId>maven-war-plugin</artifactId>
  6. <configuration>
  7. <failOnMissingWebXml>false</failOnMissingWebXml>
  8. </configuration>
  9. </plugin>
  10. <plugin>
  11. <groupId>org.springframework.boot</groupId>
  12. <artifactId>spring-boot-maven-plugin</artifactId>
  13. <configuration>
  14. <mainClass>whm.SpringbootTestApplication</mainClass>
  15. </configuration>
  16. </plugin>
  17. </plugins>
  18. </build>

启动war包

  1. java -jar web-0.0.1-SNAPSHOT.war

3、目录启动

将 web-0.0.1-SNAPSHOT.jar解压,进入解压后的目录web-0.0.1-SNAPSHOT,里面会有两文件夹,进入META-INF文件夹,打开MANIFEST.MF

  1. Manifest-Version: 1.0
  2. Implementation-Title: web
  3. Implementation-Version: 0.0.1-SNAPSHOT
  4. Start-Class: whm.SpringbootTestApplication
  5. Spring-Boot-Classes: BOOT-INF/classes/
  6. Spring-Boot-Lib: BOOT-INF/lib/
  7. Build-Jdk-Spec: 1.8
  8. Spring-Boot-Version: 2.1.7.RELEASE
  9. Created-By: Maven Archiver 3.4.0
  10. Main-Class: org.springframework.boot.loader.JarLauncher

启动org.springframework.boot.loader.JarLauncher

  1. java org.springframework.boot.loader.JarLauncher

发表评论

表情:
评论列表 (有 0 条评论,561人围观)

还没有评论,来说两句吧...

相关阅读