spring boot 打包为war包报错:提示缺少web.xml

Case

执行命令maven package将spring boot项目打成war包报错:

$ mvn package
//...
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war 
(default-war) on project spring4-mvc-maven-ajax-example: 

Error assembling WAR: webxml attribute is required 
(or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]

Cause

spring boot项目中引用了依赖包spring-boot-starter-web。该包中引用的spring-boot-starter-tomcat里包含了tomcat嵌入式servlet容器,其不同版本实现的是不同的servlet版本规范。servlet规范与tomcat两者版本对应关系如下:

Servlet/JSP Spec

Apache Tomcat version

Actual release revision

Minimum Java Version

3.0/2.2

7.0.x

7.0.12

1.6

2.5/2.1

6.0.x

6.0.32

1.5

2.4/2.0

5.5.x

5.5.33

1.4

2.3/1.2

4.1.x (archived)

4.1.40 (archived)

1.3

2.2/1.1

3.3.x (archived)

3.3.2 (archived)

1.1

Solution

1. For servlet container < 3, make sure WEB-INF/web.xml file exists.

Default location for web.xml is "/src/main/webapp/WEB-INF/web.xml"

2. For servlet container >=3, and NO web.xml web application, declares the following maven-war-plugin plugin, and set the failOnMissingWebXml option to false.

pom.xml

<build>
<plugins>

	<plugin>
		<groupId>org.apache.maven.plugins</groupId>
		<artifactId>maven-war-plugin</artifactId>
		<version>2.6</version>
		<configuration>
			<failOnMissingWebXml>false</failOnMissingWebXml>
		</configuration>
	</plugin>

</plugins>
  </build>

转载于:https://my.oschina.net/yqz/blog/847452

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值