创建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>

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

  1. [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下 报错如下: xxxxxx@xxxxxxxx /d/secSe ...

  2. [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 (defau ...

  3. [ERROR] Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:2.3.1:jar (default-jar) on

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:2.3.1:jar (default-jar) on ...

  4. [ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project child02

    maven打包成war时,报错: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (d ...

  5. [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project triage: Compilation failure [ERROR] No compiler is provided in this environment.

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-c ...

  6. [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile (default-compile) on project taotao-manager-pojo: Compilation failure

    运行maven项目时报错 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compi ...

  7. Maven进行install的时候报错,COMPILATION ERROR : Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.13:test (default-test) on project cmu: There are test failures.

    maven进行install的时候,test类里面报错: COMPILATION ERROR : [INFO] -------------------------------------------- ...

  8. [ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.4: install (default-install) on project authorizationManagement-service: Failed to install metadata com.dmsdbj.itoo:autho

    今天在打包时遇到这个问题: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.4: inst ...

  9. mvn clean package:[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12

    原文地址:https://www.cnblogs.com/lxcy/p/8279899.html 事故现场: 解决办法: 一是命令行, mvn clean package -Dmaven.test.s ...

随机推荐

  1. JuJu团队1月4号工作汇报

    JuJu团队1月4号工作汇报 JuJu   Scrum 团队成员 今日工作 剩余任务 困难 飞飞 将model嵌入GUI 美化UI 无 婷婷 调试代码 提升acc 无 恩升 -- 写python版本的 ...

  2. Arm-Linux 移植 Ubuntu

    前言: 这篇文章介绍如何构建一个完整基于ARM的Ubuntu系统. 由于改文章当初写的时候是发表在国外产品论坛上面,故保留了原文内容. 使用到的硬件平台:Geekbox 补充说明: 虽然Geekbox ...

  3. Java笔记--泛型

    1.泛型解决元素存储的安全性问题:解决获取数据元素时,需要类型强转的问题. --泛型的核心思想:把一个集合中的内容限制为一个特定的数据类型. 2.泛型的使用 1)在集合中使用 2)自定义泛型类.泛型接 ...

  4. Day6 - H - Balanced Lineup POJ - 3264

    For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One d ...

  5. 0203 生成mysql的数据库的数据字典

    原理 项目的数据库字典表是一个很重要的文档.通过此文档可以清晰的了解数据表结构及开发者的设计意图. 通常为了方便我都是直接在数据库中建表,然后通过工具导出数据字典. 在Mysql数据库中有一个info ...

  6. 034、Java中自增之++在前面的写法

    01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...

  7. Python中基于Unpacking与Packing进行分割,组合操作的嵌套元组数据结构的应用

    对于二叉树,图等,Python可采用基于Packing与Unpacking形成的嵌套元组数据结构来模拟,这里Packing指,比如a=b,c则,a就成了一个包含b,c的元组,Unpacking是指,比 ...

  8. 从零到Django大牛的的进阶之路01

    搭建 创建虚拟环境 mkvirtualenv django_py3_1.11 -p python3 安装Django pip install django==1.11.11 创建工程 django-a ...

  9. .Net有哪些大型项目、大型网站的案例?

    .Net开发的部分知名网站案例:http://www.godaddy.com 全球最大域名注册商http://www.ips.com 环迅支付,国内最早的在线支付平台http://www.icbc.c ...

  10. .NET配置问题

    Ext.NET MVC 配置问题总结       随着VS版本和.NET MVC版本.EF的版本的不断更新,虽然很多功能随着版本的提升而更完善,但对于旧版本开发的软件就有点悲催了,或许很多开发者都遇到 ...