用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应用正常运行。

经过这两步,问题解决。

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