web.xml is missing and is set to true

Error: web.xml is missing and <failOnMissingWebXml> is set to true
我们在创建一个 Maven 项目时,如果选择以 war 包的形式打包,经常会遇到这么一个错误:
Error: web.xml is missing and <failOnMissingWebXml> is set to true
cvc-elt.1: Cannot find the declaration of element ‘project’.
web.xml is missing and is set to true

这个错误的原因就是项目创建完成后,webapp 这个 folder 下没有自动创建 WEB-INF folder 以及它下面的 web.xml. 一般的解决办法是去别的项目复制过来就行了。

下面提供一种“高大上”的解决办法:

  1. 右键项目名,点击 Properties,选择 Project Facets,取消勾选如下项,然后点击 Apply:
    Error: web.xml is missing and <failOnMissingWebXml> is set to true
    2.重新勾选上一步取消勾选的地方,版本选择 2.5 ,然后点击下面的链接:
    Error: web.xml is missing and <failOnMissingWebXml> is set to true

3.在 Content directory 栏输入如下内容,并勾选下图中标记的选项,然后点击 Apply and Close。
Error: web.xml is missing and <failOnMissingWebXml> is set to true
4.最后,如果没看到变化,是因为没有 update。 右击项目,选中 Maven , 点击 Update Project, OK.

相关文章:

  • 2022-01-13
  • 2021-06-25
  • 2021-10-24
  • 2021-04-18
  • 2021-10-19
  • 2021-04-23
  • 2021-12-03
  • 2022-01-09
猜你喜欢
  • 2021-10-10
  • 2018-07-24
  • 2021-04-11
  • 2021-11-25
  • 2021-09-15
相关资源
相似解决方案