eclipse web.xml 丢失并且 <failOnMissingWebXml> 设置为 true
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31835033/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
web.xml is missing and <failOnMissingWebXml> is set to true
提问by Yogesh Doke
回答by Martijn Burger
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.xml 文件,因为它是一个 Web 应用程序,如<packaging>war</packaging>
. 但是,对于最近的 Web 应用程序,web.xml 文件完全是可选的。Maven 需要赶上这个约定。将此添加到您的 mavenpom.xml
以让 maven 赶上web.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>
This is a better solution than adding an empty web.xml
because this way your final product stays clean, your are just changing your build parameters.
这是比添加空的更好的解决方案,web.xml
因为这样您的最终产品保持干净,您只需更改构建参数。
For more current versions of maven you can also use the shorter version:
对于 maven 的最新版本,您还可以使用较短的版本:
<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
回答by Wojciechu
回答by Yuci
If you already have web.xml under /src/main/webapp/WEB-INF but you still get error "web.xml is missing and is set to true", you could check if you have included /src/main/webappin your project source.
如果您已经在/ src目录/主/ web应用/ WEB-INF的web.xml,但你仍然得到错误“的web.xml是失踪,被设置为true”,你可以检查是否已包括/ src目录/主/ web应用程序中你的项目来源。
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。保存设置,然后,
- 转到 Eclipse 菜单 Project -> Clean... 并清理项目,错误应该消失。
(I verified this with Eclipse Mars)
(我用 Eclipse Mars 验证了这一点)
回答by milan.latinovic
If you use Spring Tool Suite, option for Generate Deployment Descriptor Stub is moved under Java EE Tools, so you:
如果您使用 Spring Tool Suite,Generate Deployment Descriptor Stub 选项将移至 Java EE Tools 下,因此您:
- Right clickon your project
- Select Java EE Tools
- Select Generate Deployment Descriptor Stub option
- 右键单击您的项目
- 选择Java EE 工具
- 选择生成部署描述符存根选项
This will create web.xml file inside src/main/webapp/WEB-INF/ folder, and of course remove error from Maven's pom.xml file.
这将在 src/main/webapp/WEB-INF/ 文件夹中创建 web.xml 文件,当然还会从 Maven 的 pom.xml 文件中删除错误。
回答by Tung
I have the same problem. After studying and googling, I have resolved my problem:
我也有同样的问题。经过学习和谷歌搜索,我解决了我的问题:
Right click on the project folder, go to Java EE Tools
, select Generate Deployment Descriptor Stub
. This will create web.xml
in the folder src/main/webapp/WEB-INF
.
右键单击项目文件夹,转到Java EE Tools
,选择Generate Deployment Descriptor Stub
。这将web.xml
在文件夹中创建src/main/webapp/WEB-INF
.
回答by liam mooney
You can also do this which is less verbose
你也可以这样做,这是不那么冗长
<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
回答by u4506703
Eclipse recognizes incorrect default webapp
directory.
Therefore we should set clearly it by maven-war-plugin
.
Eclipse 识别出错误的默认webapp
目录。因此我们应该通过 明确它maven-war-plugin
。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<webappDirectory>src/main/webapp</webappDirectory>
</configuration>
</plugin>
</plugins>
</build>
Once saving this setting, the error will never occour if removed it. (I cannot explain why.)
保存此设置后,如果删除它,错误将永远不会发生。(我无法解释为什么。)
回答by Boris Treukhov
I had the same problem, even though I had 'src/main/webapp/WEB-INF/'
folder with correct web.xml
.
我遇到了同样的问题,即使我有'src/main/webapp/WEB-INF/'
正确的web.xml
.
The problem disappeared after I recreated (maven->eclipse) configuration with
Maven build..
I executed mvn eclipse:clean eclipse:eclipse
问题消失后我重新创建(maven->蚀)构型与
Maven build..
我执行mvn eclipse:clean eclipse:eclipse
And then I used Maven -> Update Project
to add (eclipse->maven) plugin specific options.
然后我曾经Maven -> Update Project
添加(eclipse->maven)插件特定的选项。
回答by The Gilbert Arenas Dagger
I encountered this issue in eclipse only, everything worked fine in Maven command line, and my web.xml file existed. It was a mature project (already deployed out in production) that was impacted. My problem was tied to the eclipse metadata. There was an issue with one of the files in my .settings/ folder, specifically org.eclipse.wst.common.component had been changed. I was able to restore this file to its prior version, which resolved the issue in my case.
我只在 eclipse 中遇到过这个问题,在 Maven 命令行中一切正常,我的 web.xml 文件存在。这是一个受到影响的成熟项目(已部署在生产中)。我的问题与 eclipse 元数据有关。我的 .settings/ 文件夹中的一个文件存在问题,特别是 org.eclipse.wst.common.component 已更改。我能够将此文件恢复到其以前的版本,这解决了我的问题。
Note that Yuci's answer did not work for me, when I tried to click on Deployment Assembly in the eclipse properties, I got an error that said "the currently displayed page contains invalid values."
请注意,Yuci 的回答对我不起作用,当我尝试单击 eclipse 属性中的部署程序集时,出现错误,提示“当前显示的页面包含无效值”。
回答by Saurav
For Project with web.xml presentProject-->Properties-->Deployment Assembly,where you can add Folder src/main/webapp. Save change. Clean the project to get going.
对于带有 web.xml 的 Project,存在Project-->Properties-->Deployment Assembly,您可以在其中添加文件夹 src/main/webapp。保存更改。清理项目以开始。
For Project with web.xml not presentSet failOnMissingWebXml to false in pom.xml under properties tag.
对于不存在 web.xml 的项目在属性标记下的 pom.xml 中将 failOnMissingWebXml 设置为 false。