我收到以下错误:
装配WAR时出错:需要webxml属性(如果在更新模式下执行,则为预先存在的WEB-INF/web.xml)
我到web.xml了正确的地方projectname\src\main\webapp\WEB-INF\web.xml
可能是什么导致了这个?
Arp*_*pit 350
如果你能提供你的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>
Run Code Online (Sandbox Code Playgroud)
小智 135
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
这个解决方案对我有用(之前我使用的是2.2).此外,我正在使用基于Java的配置Servlet 3.0,而不需要web.xml文件.
Bur*_*RAS 81
它也适合我.
<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>
Run Code Online (Sandbox Code Playgroud)
Ank*_*ain 29
这是因为您没有在web项目中包含web.xml并尝试使用maven构建war.要解决此错误,您需要在pom.xml文件中将failOnMissingWebXml设置为false.
例如:
<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
Run Code Online (Sandbox Code Playgroud)
有关详细信息,请参阅博客:https://ankurjain26.blogspot.in/2017/05/error-assembling-war-webxml-attribute.html
小智 22
如果要从基于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>
Run Code Online (Sandbox Code Playgroud)
Bon*_*oat 19
我的webXml标记的值需要看起来像这样才能工作:
<webXml>${project.basedir}\src\main\webapp\WEB-INF\web.xml</webXml>
Run Code Online (Sandbox Code Playgroud)
Cat*_*oiu 15
我有完全相同的问题,我这样解决了:
制作一个名为新文件夹WEB-INF下,src/main/webbapp然后
右键单击您的项目 - > Java EE工具 - >生成部署描述符存根
这应该产生你的 web.xml
我希望通过解决你的问题来解决这个问题:D
Mat*_*ttC 13
它确实看起来像你在正确的位置有web.xml,但即便如此,这个错误通常是由于目录结构与Maven期望看到的不匹配.例如,如果您开始使用您尝试使用Maven构建的Eclipse Web应用程序.
如果这是问题,快速解决方法是创建一个
src/main/java和一个
src/main/webapp目录(以及其他目录,如果你需要它们),只需移动你的文件.
以下是maven目录布局的概述:http: //maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html
这是个老问题,有很多答案,大部分都会或多或少有帮助;然而,有一个非常重要且仍然相关的点,没有一个答案涉及(相反,提供不同的黑客来使构建成为可能),而且我认为,这一点也不那么重要..恰恰相反.
根据您的日志消息,您正在使用 Maven,这是一个项目管理工具,严格遵循约定,优先于配置原则。
当Maven构建项目时:
Maven's Standard Directory Layout;Sun Microsystems Directory Structure StandardJava EE [web] 应用程序。您可以合并很多东西,包括 maven 插件、更改/重新配置项目根目录等,但更好和更容易的是遵循默认约定而不是配置,根据该约定,(现在是您问题的答案)有一个简单的可以使您的项目工作的步骤:只需将您的项目放在web.xml下面src\main\webapp\WEB-INF\并尝试使用mvn package.
所有其他有关的答案可能已过时,因为maven-war-plugin 使用的默认值已更改:
从 3.1.0 开始,如果项目依赖于 Servlet 3.0 API 或更新版本,则此属性默认为 false。
所以你唯一要做的就是添加
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
<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>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<tomcat.ignorePackaging>true</tomcat.ignorePackaging>
</properties>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.1.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
小智 6
如果更改默认项目路径,则必须指定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>
Run Code Online (Sandbox Code Playgroud)
根据文档,它说:如果缺少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>
Run Code Online (Sandbox Code Playgroud)
希望它更清楚
mvn-war-plugin 2.3解决了这个问题:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
</plugin>
...
Run Code Online (Sandbox Code Playgroud)
小智 5
它对我也有用.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>WebContent\WEB-INF\web.xml</webXml>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我在测试服务器上有同样的错误,但在本地没有。几分钟后,我发现 IDE 没有与 pom.xml 同步。这是我解决它的方法:
| 归档时间: |
|
| 查看次数: |
280485 次 |
| 最近记录: |