maven项目报错web.xml is missing and <failOnMissingWebXml> is set to true解决

创建一个maven管理的war项目,报这个错是因为没有web.xml文件。

解决方式一:最直接的是在webapp下创建WEB-INF目录,然后在WEB-INF目录下创建web.xml文件,如果创建的web.xml文件报错,可能是因为约束文件还没下载完成,或者文件有地方书写错误。可以使用下面的模板,当然你需要看一下你的tomcat支持的把版本。

<?xml version="1.0" encoding="UTF-8"?>  
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"  
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">  


</web-app>  

解决方式二:如果你并不需要web.xml文件,可以在pom.xml文件中添加如下配置,直接忽略报错

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

猜你喜欢

转载自blog.csdn.net/Let_me_tell_you/article/details/81089190