我收到以下错误:
汇编WAR时出错:需要webxml属性(如果在更新模式下执行,则为预先存在的WEB-INF / web.xml)
我有 web.xml 在正确的地方,这是 projectname\src\main\webapp\WEB-INF\web.xml
web.xml
projectname\src\main\webapp\WEB-INF\web.xml
可能是什么导致了这个?
它对我也有用 .
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <webXml>WebContent\WEB-INF\web.xml</webXml> </configuration> </plugin>
如果你能提供你的maven-war-plugin的代码片段会很有帮助 . 看起来 web.xml 位于正确的位置,您仍然可以尝试明确地给出位置
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <webXml>src\main\webapp\WEB-INF\web.xml</webXml> </configuration> </plugin>
<plugin> <artifactId>maven-war-plugin</artifactId> <version>2.4</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin>
这个解决方案对我有用(之前我使用的是2.2) . 此外,我正在使用基于Java的配置Servlet 3.0,而不需要web.xml文件 .
它也适合我 .
<project> ..... <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <webXml>WebContent\WEB-INF\web.xml</webXml> </configuration> </plugin> </plugins> </build> </project>
这是因为您没有在web项目中包含web.xml并尝试使用maven构建war . 要解决此错误,您需要在pom.xml文件中将 failOnMissingWebXml 设置为 false .
例如:
<properties> <failOnMissingWebXml>false</failOnMissingWebXml> </properties>
有关详细信息,请参阅博客:https://ankurjain26.blogspot.in/2017/05/error-assembling-war-webxml-attribute.html
我的webXml标记的值需要看起来像这样才能工作:
<webXml>${project.basedir}\src\main\webapp\WEB-INF\web.xml</webXml>
如果要从基于XML的配置迁移到基于Java的配置,并且通过实现WebApplicationInitializer删除了对web.xml的需求,则只需删除对web.xml文件的要求即可 .
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.6</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> ... </configuration>
它确实看起来像你在正确的位置有web.xml,但即便如此,这个错误通常是由于目录结构与Maven期望看到的不匹配 . 例如,如果您开始使用您尝试使用Maven构建的Eclipse Web应用程序 .
如果这是问题,快速解决方法是创建一个src/main/java 和asrc/main/webapp 目录(以及其他目录,如果您需要它们)并只移动您的文件 .
src/main/java
src/main/webapp
以下是maven目录布局的概述:http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html
我有完全相同的问题,我这样解决了:
在 src/main/webbapp 下创建一个名为 WEB-INF 的新文件夹
src/main/webbapp
WEB-INF
右键单击您的项目 - > Java EE工具 - >生成部署描述符存根
这应该会产生 web.xml
我希望通过解决你的问题来解决这个问题:D
如果更改默认项目路径,则必须指定web.xml文件的位置,例如:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.5</version> <configuration> <webXml>src\main\web\WEB-INF\web.xml</webXml> </configuration> </plugin>
mvn-war-plugin 2.3解决了这个问题:
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.3</version> </plugin> ...
根据文档,它说:如果缺少web.xml文件,是否使构建失败 . 如果您希望在没有web.xml文件的情况下构建WAR,请设置为false . 如果要构建没有web.xml文件的叠加层,这可能很有用 . 默认值为:true . 用户属性为:failOnMissingWebXml .
<plugin> <artifactId>maven-war-plugin</artifactId> <version>2.1.1</version> <extensions>false</extensions> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin>
希望它更清楚
我在测试服务器上遇到了同样的错误,但在本地没有 . 几分钟后,我发现IDE未与pom.xml同步 . 以下是我如何解决它:
右键单击项目文件夹
在上下文菜单中,选择"Java EE Tools"然后"Generate Deployment Descriptor Stub"
它将创建web.xml .
在上下文菜单中,选择"Open Module Settings",然后单击以添加Web部署描述符 .
然后您可以更改 path to your descriptor 或 Web Ressource Directories 以及右侧 .
然后你会得到类似的东西:
确保将pom.xml正确放置在Project文件夹中 . 而不是在目标文件夹或其他任何地方 .
看起来pom.xml没有相对对齐 .
您的文件夹结构是否已更改,因此文件不再是 /src/main/webapp/WEB-INF/web.xml ?
为了解决这个问题,我给我的web文件夹命名为webapp并将其放在src / main中 . Maven似乎默认在 /src/main/webapp/WEB-INF/web.xml 寻找web.xml . 如果你这样做,那么你不会改变你的文件夹结构,你的构建最近停止工作,这可能是原因 .
Note: 这是一篇旧帖子,但发布的解决方案并没有指出为什么工作版本会突然停止工作 .
发生此错误是因为 you say Maven to pakage files to war .
<packaging>war</packaging>
Do you really needs war? If not, put jar there. 这是完整的代码:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <version>1.0-SNAPSHOT</version> <groupId>com.your.groupid</groupId> <artifactId>artifactid</artifactId> <packaging>jar</packaging>
16 回答
它对我也有用 .
如果你能提供你的maven-war-plugin的代码片段会很有帮助 . 看起来
web.xml
位于正确的位置,您仍然可以尝试明确地给出位置这个解决方案对我有用(之前我使用的是2.2) . 此外,我正在使用基于Java的配置Servlet 3.0,而不需要web.xml文件 .
它也适合我 .
这是因为您没有在web项目中包含web.xml并尝试使用maven构建war . 要解决此错误,您需要在pom.xml文件中将 failOnMissingWebXml 设置为 false .
例如:
有关详细信息,请参阅博客:https://ankurjain26.blogspot.in/2017/05/error-assembling-war-webxml-attribute.html
我的webXml标记的值需要看起来像这样才能工作:
如果要从基于XML的配置迁移到基于Java的配置,并且通过实现WebApplicationInitializer删除了对web.xml的需求,则只需删除对web.xml文件的要求即可 .
它确实看起来像你在正确的位置有web.xml,但即便如此,这个错误通常是由于目录结构与Maven期望看到的不匹配 . 例如,如果您开始使用您尝试使用Maven构建的Eclipse Web应用程序 .
如果这是问题,快速解决方法是创建一个
src/main/java
和asrc/main/webapp
目录(以及其他目录,如果您需要它们)并只移动您的文件 .以下是maven目录布局的概述:http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html
我有完全相同的问题,我这样解决了:
在
src/main/webbapp
下创建一个名为WEB-INF
的新文件夹右键单击您的项目 - > Java EE工具 - >生成部署描述符存根
这应该会产生
web.xml
我希望通过解决你的问题来解决这个问题:D
如果更改默认项目路径,则必须指定web.xml文件的位置,例如:
mvn-war-plugin 2.3解决了这个问题:
根据文档,它说:如果缺少web.xml文件,是否使构建失败 . 如果您希望在没有web.xml文件的情况下构建WAR,请设置为false . 如果要构建没有web.xml文件的叠加层,这可能很有用 . 默认值为:true . 用户属性为:failOnMissingWebXml .
希望它更清楚
我在测试服务器上遇到了同样的错误,但在本地没有 . 几分钟后,我发现IDE未与pom.xml同步 . 以下是我如何解决它:
使用Eclipse重新生成部署描述符
右键单击项目文件夹
在上下文菜单中,选择"Java EE Tools"然后"Generate Deployment Descriptor Stub"
它将创建web.xml .
使用IntelliJ重新生成部署描述符
右键单击项目文件夹
在上下文菜单中,选择"Open Module Settings",然后单击以添加Web部署描述符 .
然后您可以更改 path to your descriptor 或 Web Ressource Directories 以及右侧 .
然后你会得到类似的东西:
确保将pom.xml正确放置在Project文件夹中 . 而不是在目标文件夹或其他任何地方 .
看起来pom.xml没有相对对齐 .
您的文件夹结构是否已更改,因此文件不再是 /src/main/webapp/WEB-INF/web.xml ?
为了解决这个问题,我给我的web文件夹命名为webapp并将其放在src / main中 . Maven似乎默认在 /src/main/webapp/WEB-INF/web.xml 寻找web.xml . 如果你这样做,那么你不会改变你的文件夹结构,你的构建最近停止工作,这可能是原因 .
Note: 这是一篇旧帖子,但发布的解决方案并没有指出为什么工作版本会突然停止工作 .
发生此错误是因为 you say Maven to pakage files to war .
Do you really needs war? If not, put jar there. 这是完整的代码: