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

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

[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]
[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 <goals> -rf :model

二、解决方案一

1、错误原因:

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

SpringBoot——Failed to execute goal org.springframework.boot:spring-boot-maven-plugin_第1张图片

SpringBoot——Failed to execute goal org.springframework.boot:spring-boot-maven-plugin_第2张图片

2、解决:

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

3、注意:

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

三、解决方案二

1、在根pom文件中加入:

<pluginRepositories>
		<pluginRepository>
			<id>spring-snapshots</id>
			<url>https://repo.spring.io/snapshot</url>
		</pluginRepository>
		<pluginRepository>
			<id>spring-milestones</id>
			<url>https://repo.spring.io/milestone</url>
		</pluginRepository>
	</pluginRepositories>

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

 <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>com.whm.SpringbootTestApplication</mainClass>
                </configuration>
            </plugin>
        </plugins>
  </build>

四、启动方式

1、jar启动

java -jar web-0.0.1-SNAPSHOT.jar

2、war启动

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

<packaging>war</packaging>

<build>
        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>whm.SpringbootTestApplication</mainClass>
                </configuration>
            </plugin>
        </plugins>
 </build>

启动war包

java -jar web-0.0.1-SNAPSHOT.war

3、目录启动

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

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

启动org.springframework.boot.loader.JarLauncher

java org.springframework.boot.loader.JarLauncher

你可能感兴趣的:(*【Java】,——————日常(Java),——————框架)