"webxml attribute is required" error in Maven

333,818

Solution 1

It would be helpful if you can provide a code snippet of your maven-war-plugin. Looks like the web.xml is at right place, still you can try and give the location explicitly

<plugin>            
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <configuration>
    <webXml>src\main\webapp\WEB-INF\web.xml</webXml>        
  </configuration>
</plugin>

Solution 2

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </configuration>
</plugin>

This solution works for me (I was using 2.2 before). Also, I am using Java Based Configuration for Servlet 3.0 and no need to have web.xml file.

Solution 3

It works perfectly for me too.

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

Solution 4

This is because you have not included web.xml in your web project and trying to build war using maven. To resolve this error, you need to set the failOnMissingWebXml to false in pom.xml file.

For example:

<properties>
    <failOnMissingWebXml>false</failOnMissingWebXml>   
</properties>

Please see the blog for more details: https://ankurjain26.blogspot.in/2017/05/error-assembling-war-webxml-attribute.html

Solution 5

If you are migrating from XML-based to Java-based configuration and you have removed the need for web.xml by implementing WebApplicationInitializer, simply remove the requirement for the web.xml file to be present.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <failOnMissingWebXml>false</failOnMissingWebXml>
        ... 
    </configuration>
Share:
333,818
user617966
Author by

user617966

Updated on January 23, 2021

Comments

  • user617966
    user617966 over 3 years

    I am getting the following error:

    Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)

    I have got web.xml in right place which is projectname\src\main\webapp\WEB-INF\web.xml

    What could be causing this?

  • Buffalo
    Buffalo over 12 years
    Worked for me too, thanks. But what's the default location where Maven searches?
  • Ram
    Ram over 11 years
    Above works when facets are enabled and WebContent is the folder where web.xml goes in.
  • xverges
    xverges about 10 years
    I just updated the maven war plugin from 2.1.1 to 2.4, and the need to make explicit the default location wen away.
  • erwineberhard
    erwineberhard over 8 years
    It works, but the logs says now: WEB-INF\web.xml already added, skipping. That's weird, when I don't add this, I got the error.
  • Adam
    Adam over 8 years
    exactly! Couldn't figure it out until I saw I had just a slash at the beginning <warSourceDirectory>\src\main\webapp</warSourceDirectory> doesn't work! Not in v2.6
  • Prachi
    Prachi about 8 years
    Same as erwineberhard. WEB-INF\web.xml already added, skipping
  • Paul Verest
    Paul Verest almost 8 years
    similar answer was given before
  • shabby
    shabby over 7 years
    and in netbeans you would: right click the project node> New > Other > Web > Standard Deployment Descriptor (web.xml).
  • Vic Torious
    Vic Torious over 7 years
    You might want to update your answer for ItelliJ IDEA users - IntelliJ creates another project structure so it would be <webXml>web\WEB-INF\web.xml</webXml>
  • Bunny Joel
    Bunny Joel over 6 years
    tried your answer but still got the same error instead of that I did this "C:\Users\xxxx\Videos\maven-projects\my-project\src\webapp\W‌​EB-INF" and worked good. I dont know what is the problem. Its my luck. Thank you
  • Giorgi Tsiklauri
    Giorgi Tsiklauri over 5 years
    jar and war are completely different stories. I think war is needed here, as the archive is getting deployed to web container and is not ran separately as a standalone jar application.
  • Eisenknurr
    Eisenknurr about 5 years
    The versions 3.x of that plugin now have failOnMissingWebXml default to false. So, <plugin> <artifactId>maven-war-plugin</artifactId> <version>3.2.3</version> </plugin> should suffice.
  • JGlass
    JGlass almost 5 years
    worked for me as I was and still am using jboss-web.xml - thanks!
  • foo
    foo over 4 years
    This one gives context, where exactly the line needs to go.
  • blueSky
    blueSky about 4 years
    I have a project that does not have web.xml, and this worked for me. Maven build is successful.
  • Bhushan Karmarkar
    Bhushan Karmarkar over 2 years
    I had to add <groupId>org.apache.maven.plugins</groupId> just before the artifactId, then it worked. Thanks