我得到以下错误:

装配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>

其他回答

确保在Project文件夹中正确放置了pom.xml。而不是在目标文件夹或其他任何地方。

看起来pom.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>

我在测试服务器上有同样的错误,但不是在本地。几分钟后,我发现IDE没有与pom.xml同步。以下是我的解决方法:

使用Eclipse重新生成部署描述符

右键单击项目文件夹 在上下文菜单中,选择“Java EE工具”,然后选择“生成部署描述符存根” 它将创建web.xml文件。

使用IntelliJ重新生成部署描述符

右键单击项目文件夹 在上下文菜单中,选择“打开模块设置”,然后单击+添加web部署描述符。 然后你可以改变你的描述符或Web资源目录的路径。 然后你会得到这样的东西:

在编译war之前,请确保运行mvn install。