[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war

创建springboot项目,且不采用<parent>引入springboot时,pom.xml如下:

<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo-without-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

    <name>demo-without-parent</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <maven.compiler.encoding>UTF-8</maven.compiler.encoding>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>2.0.2.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

执行

mvn clean install 

控制台报错:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war

原因:当设置为war时,web.xml必须存在。

解决:可通过插件配置属性将其忽略。

首先,spring-boot-dependencies 这个pom文件,找到

<maven-war-plugin.version>3.1.0</maven-war-plugin.version>

找到版本号是3.1.0

然后,在项目的pom.xml中,加入

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.1.0</version>
</plugin>

版本号必须与spring-boot-dependencies中maven-war-plugin-version版本号一致。

再次运行mvn clean install ,提示打包成功。

在idea中,运行启动类,成功启动。但是

java -jar demo-without-parent-0.0.1-SNAPSHOT.war

提示:demo-without-parent-0.0.1-SNAPSHOT.war中没有主清单属性

因为,maven-war-plugin的确执行了,但是spring-boot-maven-plugin插件却没有执行,原因在于该插件未指定版本,故设置版本号,依旧是从spring-boot-dependencies中找对应的版本号:2.0.2.RELEASE

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>2.0.2.RELEASE</version>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
        </execution>
    </executions>
</plugin>

重新执行

mvn clean install ,

mvn clean install
java -jar demo-without-parent-0.0.1-SNAPSHOT.war

成功。

最后总结:

1)、maven-war-plugin插件新老版本差异:
    2.2:项目中WEB-INF下必须存在web.xml
    3.1.0:不需要依赖web.xml
    而且,版本号必须与所引入的spring-boot-dependencies下的maven-war-plugin版本号一致。

2)、spring-boot-maven-plugin插件需要配置repackage,否则不会添加spring boot 引导依赖,进而无法引导当前应用。

3)、根据使用习惯通常不会采用spring-boot-dependencies

附,完整pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo-without-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

    <name>demo-without-parent</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <maven.compiler.encoding>UTF-8</maven.compiler.encoding>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>2.0.2.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.0.2.RELEASE</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.1.0</version>
            </plugin>
        </plugins>
    </build>

</project>

原文地址:https://www.cnblogs.com/yaoyuan2/p/11703540.html

时间: 2024-10-07 23:37:14

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war的相关文章

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.4:create (default-cli) on project standalone-pom: Unable to parse configuration of 3: mojo org.apache.maven.plugins:

问题: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.4:create (default-cli)  on project standalone-pom: Unable to parse configuration of 3:  mojo org.apache.maven.plugins:maven-archetype-plugin:2.4:create for parameter

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.3.1:

security-sdk-1.0.jar已经存在于D:/secServerSDK-test/src/main/resources/lib下 报错如下: [email protected] /d/secServerSDK-test/src/main/resources/lib$ mvn install:install-file -Dfile=security-sdk-1.0.jar -DgroupId=com.jd.security -DartifactId=security-sdk -Dvers

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.8:unpack (unpack) on project sq-integral-web: Unable to find artifact.

1.问题描述 项目maven打包报上述错误, 但是小伙伴运行好使. 2.问题解决 是idea工程编码(gbk)和项目编码(utf-8)不一致 idea->file->Other Settings->Default Settings 把编码改成一致

Maven Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean Failed to delete access_log

I'm trying to run simple struts project using maven and tomcat. When I'm trying to exucute next goals:clean install tomcat7:run ,there is an error : [ERROR] Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean (default-clean)

Maven错误“Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.4:create ”解决

用maven3新建一个项目时,输入的命令如下: mvn archetype:create 出现错误如下: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.4:create (default-cli) on project standalone-pom: Unable to parse configuration of mojo org.apache.maven.plugins:mav

Maven项目报错:Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean (default-clea

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean (default-clean) on project study-search: Failed to clean project: Failed to delete D:\Pxxtarget\tomcat\logs\access_log.2017-3-24 [ERROR] [ERROR] To see the full stac

Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (dist) on project hadoop-kms: An Ant BuildException has occured

编译cdh版hadoop2.5.0出现的问题 系统: CentOs66 64位 JDK:1.7 Maven: 3.0.5 Protobuf: libprotoc 2.5.0 编译命令: mvn package -DskipTests -Pdist,native **************************************************************************************** [INFO] -----------------------

mvn install 报错Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2 错误: 找不到符号

报错信息 在Eclipse中执行mvn install时,console端显示如下报错信息: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project ERP: Compilation failure: Compilation failure: [ERROR] \test01\src\main\java\HStyl

Maven创建项目: Failed to execute goal org.apache.maven.plugin( mvn archetype:create)

一.概述: 在使用mvn 命令mvn archetype:create -DgroupId=com.chuanliu.c11 -DartifactId=c11searcher在控制创建maven项目和pom项目时,没有创建成功,错误信息如下: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.4:create (default-cli)  on project standalone-p