pom.xml出現web.xml is missing and <failOnMissingWebXml> is set to true解決方案
提示信息應該能看懂。也就是缺少了web.xml文件,<failOnMissingWebXml>被設置成true了。
搜索了一下,Stack Overflow上的答案解決了問題,分享一下。
目前被頂次數最多的回答原文如下:
This is a maven error. It says that it is expecting a web.xml file in your project because it is a web application, as indicated by <packaging>war</packaging>
. However, for recent web applications a web.xml file is totally optional. Maven needs to catch up to this convention. Add this to your maven pom.xml
to let maven catch up and you don‘t need to add a useless web.xml
to your project:
大意是說這是一個Maven錯誤,在最近的web應用開發中web.xml文件已經變得可有可無了。不過Maven還沒有跟上這一變化,我們只要在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>
“告知”maven即可。這樣做的好處是我們不必在項目生中成一個無用的web.xml文件。在更新版本(具體從哪一個版本開始我也不知道~~)的maven中已經不存在web.xml文件缺失的問題,我們只需要處理<failOnMissingWebXml>被設置成tue的問題即可。也就是在pom.xml中添加如下配置即可。
<properties> <failOnMissingWebXml>false</failOnMissingWebXml> </properties>
其他方案:(生成web.xml——>部署運行時文件路徑)
you can do it also like this:
- Right click on Deployment Descriptor in Project Explorer.
- Select Generate Deployment Descriptor Stub.
It will generate WEB-INF folder in src/main/webapp and an web.xml in it.
這是被采納方案,也就是說在項目瀏覽器中右鍵單擊Deloyment Descriptor,選擇生成部署描述符存根:Generate Deployment Descriptor Stub。
操作後會在項目的src/main/webapp/WEB-INF目錄下生成web.xml文件。我按照這個方法生成了web.xml文件,但是仍然報錯。如果你也是的話可以接著往下看。
Here are the steps you can follow:
- You can check this by right clicking your project, and open its Properties dialogue, and then "Deployment Assembly", where you can add Folder /src/main/webapp. Save the setting, and then,
- Go to Eclipse menu Project -> Clean... and clean the project, and the error should go away.
此時需要對src/main/webapp文件進行運行時的路徑部署,以保證服務器正常運行。
也就是說需要部署一下src/main/webapp(剛生成的web.xml就在該文件夾下)文件夾,Deployment的作用是會在運行時將相應的resource復制到web服務器的相應目錄下(通過Deploy Path指定),保證web應用正常運行。
經過這兩步,問題解決。
pom.xml出現web.xml is missing and <failOnMissingWebXml> is set to true解決方案