我得到以下错误:
装配WAR: webxml属性是必需的(如果以更新模式执行,则需要预先存在的WEB-INF/web.xml)
我有web.xml在正确的地方,这是projectname\src\main\webapp\WEB-INF\web.xml
是什么导致了这种情况?
我得到以下错误:
装配WAR: webxml属性是必需的(如果以更新模式执行,则需要预先存在的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。
<packaging>war</packaging>
你真的需要战争吗?如果没有,把罐子放在那里。 以下是完整的代码:
<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>
如果你能提供你的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>
这对我来说也是完美的。
<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.xml在正确的位置,但即使如此,这个错误通常是由目录结构与Maven期望看到的不匹配引起的。例如,如果您从一个试图用Maven构建的Eclipse web应用程序开始。
如果这是问题所在,一个快速的解决方法是创建一个 Src /main/java和a Src /main/webapp目录(和其他目录,如果你需要他们),只是移动你的文件。
下面是maven目录布局的概述: http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html
在编译war之前,请确保运行mvn install。