组装WAR的Maven错误:使用纯Java Based Configuration构建SpringMVC项目时不需要webxml属性,也没有xml的 [英] Maven Error assembling WAR: webxml attribute is required when building the SpringMVC project with pure Java Based Configuration and no xml's
问题描述
我正在使用纯Java配置开发Spring MVC项目。我在进行Maven干净安装时收到以下错误。
I am developing a Spring MVC project with pure Java based configuration. I am getting the error below when I do a Maven clean install.
无法执行目标
org.apache.maven。插件:maven-war-plugin:2.2:war(默认战争)on
项目SpringMVC-ShoppingCart:组装WAR时出错:webxml属性需要
(或者预先存在的WEB-INF / web.xml)如果在更新
模式下执行) - > [帮助1]
Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project SpringMVC-ShoppingCart: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]
错误说 web缺少.xml
,但由于我使用的是基于纯Java的配置,因此我没有。
The error says that web.xml
is missing, but I did not have one since I used pure Java based configuration.
如何确保项目构建和在没有 web.xml的情况下创建war文件
?
How to make sure that the project builds and creates war file without web.xml
?
推荐答案
发生此错误是因为 maven-war-plugin
<在版本2.6或更低版本中,/ a>默认情况下会在WAR项目中出现 src / main / webapp / web.xml
文件,但它没有找到它。
This error happens because the maven-war-plugin
, in version 2.6 or lower, expects by default a src/main/webapp/web.xml
file to be present in your WAR project, and it didn't find it.
从插件版本3.0.0开始,存在 web。 xml
默认情况下不再是强制性的:
As of version 3.0.0 of the plugin, the presence of a web.xml
is not mandatory by default anymore:
failOnMissingWebXml
的默认值已从<更改code> true 到false
。
这意味着直接升级插件可以解决问题。您可以在POM中添加以下配置:
This means that upgrading the plugin directly solves the issue. You can add the following configuration in your POM:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
</plugin>
原因是自Servlet 3.0起, web.xml $ Web应用程序中不再需要c $ c>文件,可以用注释替换以具有基于Java的配置( MWAR-262 )。但是,由于您的项目可能不使用注释来替换此文件,在这种情况下实际上可能缺少
web.xml
,因此在版本3.0.1中添加了一个健全性检查。插件,以确保注释 @WebServlet
位于WAR项目的编译类路径中( MWAR-396 )。如果不是,并且项目中没有 web.xml
文件,默认情况下该插件仍会失败。
The reason is that since Servlet 3.0, the web.xml
file is no longer needed in a web application, and can be replaced with annotations to have a Java-based configuration (MWAR-262). However, since your project might not use annotations to replace this file, in which case the web.xml
could actually be missing, a sanity check was added in version 3.0.1 of the plugin to make sure that the annotation @WebServlet
is in the compile classpath of your WAR project (MWAR-396). If it isn't, and there is no web.xml
file in your project, the plugin will still fail by default.
如果您只是希望插件明确忽略丢失的 web.xml
文件,无论注释的用法如何,您都可以设置 failOnMissingWebXml
参数为 false
。示例配置为:
If you just want the plugin to explicitly ignore a missing web.xml
file, regardless of the usage of annotations, you can set the failOnMissingWebXml
parameter to false
. A sample configuration would be:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
这篇关于组装WAR的Maven错误:使用纯Java Based Configuration构建SpringMVC项目时不需要webxml属性,也没有xml的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!