我得到以下错误:

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

我有web.xml在正确的地方,这是projectname\src\main\webapp\WEB-INF\web.xml

是什么导致了这种情况?


当前回答

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

看起来pom.xml没有相对对齐。

其他回答

如果你改变默认的项目路径,你必须指定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>
<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </configuration>
</plugin>

这个解决方案适合我(我以前使用的是2.2)。此外,我使用基于Java的Servlet 3.0配置,不需要有web.xml文件。

这是因为您没有在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

根据文档,它说:如果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>

希望它能让你更清楚

如果你能提供你的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>