在STS中创建好一个maven项目后,项目下的target文件中的pom.xml文件报错,错误提示为:
web.xml is missing and
<failOnMissingWebXml>
is set to true
根据提示我们知道,项目中缺少了web.xml文件,因此这里提供以下两种解决办法:
一、如果你的项目是一个web项目,可以通过以下方式增加一个web.xml。
步骤:
①左键选中创建的项目,单击右键选择“Java EE Tools”;
②选择其中的"Generate Deployment Descriptor Stub",问题解决。
二、如果不是web项目,需要我们自己手动对pom.xml文件进行简单的配置。具体配置在<project></project>
中插入以下代码:
<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>
配置完成后,单击右键选择maven->Update Project,勾选错误位置,然后OK。最后报错解决。
补充(来自其他博客,这里记录一下):
在更新版本的maven中已经不存在web.xml文件缺失的问题,我们只需要处理"failOnMissingWebXml"被设置成tue的问题即可。也就是在pom.xml中添加如下配置即可。
<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
PS:如有错误,欢迎指正和补充。