我得到以下错误:

装配WAR: webxml属性是必需的(如果以更新模式执行,则需要预先存在的WEB-INF/web.xml)

我有web.xml在正确的地方,这是projectname\src\main\webapp\WEB-INF\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>

其他回答

如果你能提供你的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>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <webXml>WebContent\WEB-INF\web.xml</webXml>
    </configuration>
</plugin>

你的文件夹结构改变了,所以文件不再在/src/main/webapp/WEB-INF/web.xml ?

为了解决这个问题,我给我的web文件夹命名为webapp,并把它放在src/main中。Maven默认在/src/main/webapp/WEB-INF/web.xml中查找web.xml。如果这样做,则不需要显式地告诉maven 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>

如果您正在从基于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>