用Maven進行項目管理時出現web.xml is missing and is set to true怎麼解決?

缺少了web.xml文件,<failOnMissingWebXml>被設置成true了。

這是一個Maven錯誤,在最近的web應用開發中web.xml文件已經變得可有可無了。不過Maven還沒有跟上這一變化,我們只要在pom.xml文件中手動添加如下配置:

  1. <build>

  2. <plugins>

  3. <plugin>

  4. <groupId>org.apache.maven.plugins</groupId>

  5. <artifactId>maven-war-plugin</artifactId>

  6. <version>2.6</version>

  7. <configuration>

  8. <failOnMissingWebXml>false</failOnMissingWebXml>

  9. </configuration>

  10. </plugin>

  11. </plugins>

  12. </build>

“告知”maven即可。這樣做的好處是我們不必在項目生中成一個無用的web.xml文件。在更新版本(具體從哪一個版本開始我也不知道~~)的maven中已經不存在web.xml文件缺失的問題,我們只需要處理<failOnMissingWebXml>被設置成tue的問題即可。也就是在pom.xml中添加如下配置即可。

  1. <properties>

  2. <failOnMissingWebXml>false</failOnMissingWebXml>

  3. </properties>

 

其他方案:(生成web.xml——>部署運行時文件路徑)

you can do it also like this:

  1. Right click on Deployment Descriptor in Project Explorer.
  2. 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:

  1. 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,
  2. 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應用正常運行。

經過這兩步,問題解決。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章