Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.2.5.RELEASE:run (default-cli)

huangapple go评论87阅读模式
英文:

Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.2.5.RELEASE:run (default-cli)

问题

我对Spring Boot还不熟悉,正在尝试运行一个使用Maven的应用程序,通过命令运行:maven spring-boot:run。
我从Spring Initializr下载了一个Spring应用程序,并尝试在IntelliJ IDEA社区版2019.3.3中运行,但是遇到了以下错误:

> 执行目标失败
> org.springframework.boot:spring-boot-maven-plugin:2.2.5.RELEASE:run
> (default-cli) on project demo: 应用程序以退出代码1结束

我的代码如下:

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    @SpringBootApplication
    public class DemoApplication {
    
    	public static void main(String[] args) {
    		SpringApplication.run(DemoApplication.class, args);
    	}
    }

我的pom.xml文件如下:

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
    https://maven.apache.org/xsd/maven-4.0.0.xsd">
    	<modelVersion>4.0.0</modelVersion>
    	<parent>
    		<groupId>org.springframework.boot</groupId>
    		<artifactId>spring-boot-starter-parent</artifactId>
    		<version>2.2.5.RELEASE</version>
    		<relativePath/>
    		<!-- 从仓库查找父级 -->
    	</parent>
    	<groupId>com.revanth</groupId>
    	<artifactId>demo</artifactId>
    	<version>0.0.1-SNAPSHOT</version>
    	<name>demo</name>
    	<description>Spring Boot演示项目</description>
    	<properties>
    		<java.version>1.8</java.version>
    	</properties>
    	<dependencies>
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-web</artifactId>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-test</artifactId>
    			<scope>test</scope>
    			<exclusions>
    				<exclusion>
    					<groupId>org.junit.vintage</groupId>
    					<artifactId>junit-vintage-engine</artifactId>
    				</exclusion>
    			</exclusions>
    		</dependency>
    	</dependencies>
    	<build>
    		<plugins>
    			<plugin>
    				<groupId>org.springframework.boot</groupId>
    				<artifactId>spring-boot-maven-plugin</artifactId>
    			</plugin>
    		</plugins>
    	</build>
    </project>

后来我切换到NetBeans IDE并尝试运行应用程序,但是仍然遇到了相同的错误。
完整的错误堆栈信息如下:

Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.2.5.RELEASE:run (default-cli) on project demo: 应用程序以退出代码1结束 -> [帮助 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.2.5.RELEASE:run (default-cli) on project demo: 应用程序以退出代码1结束

    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    ...
    Caused by:
    org.apache.maven.plugin.MojoExecutionException: 应用程序以退出代码1结束
	at org.springframework.boot.maven.RunMojo.runWithForkedJvm(RunMojo.java:108)
	at org.springframework.boot.maven.AbstractRunMojo.doRunWithForkedJvm(AbstractRunMojo.java:292)
	at org.springframework.boot.maven.AbstractRunMojo.run(AbstractRunMojo.java:257)
	...
英文:

I am new to spring boot and am trying to run a application which runs with maven spring-boot:run.
I downloaded a spring application from spring initializr and am trying to run that in IntelliJ IDE community edition 2019.3.3 but was getting the following error:

> Failed to execute goal
> org.springframework.boot:spring-boot-maven-plugin:2.2.5.RELEASE:run
> (default-cli) on project demo: Application finished with exit code: 1

My code is:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}

My pom.xml file is:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema- 
instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<relativePath/>
<!--  lookup parent from repository  -->
</parent>
<groupId>com.revanth</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

I later changed to NetBeans IDE and tried to run the application but got the same error.
The full stack of errors are:

Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.2.5.RELEASE:run (default-cli) on project demo: Application finished with exit code: 1 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.2.5.RELEASE:run (default-cli) on project demo: Application finished with exit code: 1

at 

org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)

at

org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)

at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by:
org.apache.maven.plugin.MojoExecutionException: Application finished with exit code: 1
at org.springframework.boot.maven.RunMojo.runWithForkedJvm(RunMojo.java:108)
at org.springframework.boot.maven.AbstractRunMojo.doRunWithForkedJvm(AbstractRunMojo.java:292)
at org.springframework.boot.maven.AbstractRunMojo.run(AbstractRunMojo.java:257)
at org.springframework.boot.maven.AbstractRunMojo.execute(AbstractRunMojo.java:213)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
... 19 more

答案1

得分: 2

以上错误基本上是由于Maven中的插件问题造成的,适用于Spring Boot。

如果您想要以不同的方式运行项目,也可以这样做。

首先通过以下命令为项目创建一个jar包:

mvn clean install

然后使用普通的Java命令运行该jar包:

java -jar jar-localtion.jar

如果希望在特定配置文件下运行,可以使用以下命令:

java -Dspring.profiles.active=<env> -jar jar-localtion.jar

英文:

The above error is basically come due to plugin issue in maven for spring-boot

You can run the project in different way also if you want to run

First create a jar for the project by running

> mvn clean install

Then run the jar from normal java command

> java -jar jar-localtion.jar

if want to run with any specific profile then use this

> java -Dspring.profiles.active=<env> -jar jar-localtion.jar

答案2

得分: 0

我遇到了相同的问题,并通过在 pom.xml 中鼠标右键单击悬停在 "spring-boot-maven-plugin" 上(它是红色警告颜色),选择 "Maven",然后选择 "Download sources" 来解决它。

下载源代码大约花了几秒钟,红色警告消失了。

英文:

I have the same issue and solved it by simply clicking mouse right button hovering over "spring-boot-maven-plugin" in pom.xml (which was red warning colour), select 'Maven' and then select 'Download sources'

It took a few seconds to download sources and the red/ warning is gone.

huangapple
  • 本文由 发表于 2020年3月16日 22:56:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/60708235.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定