349

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?

Sled
  • 18,541
  • 27
  • 119
  • 168
user617966
  • 4,515
  • 4
  • 23
  • 24

22 Answers22

379

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>
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
Arpit
  • 6,212
  • 8
  • 38
  • 69
  • 38
    Worked for me too, thanks. But what's the default location where Maven searches? – Buffalo Mar 03 '12 at 08:03
  • 6
    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. – xverges May 22 '14 at 13:59
  • 2
    You might want to update your answer for ItelliJ IDEA users - IntelliJ creates another project structure so it would be web\WEB-INF\web.xml – Vic Torious Jan 04 '17 at 23:53
  • 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\WEB-INF" and worked good. I dont know what is the problem. Its my luck. Thank you – Bunny Joel Jan 11 '18 at 14:02
190
<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.

Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
Sagar
  • 2,069
  • 1
  • 14
  • 9
87

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>
Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
Burhan ARAS
  • 2,517
  • 25
  • 19
  • 6
    Above works when facets are enabled and WebContent is the folder where web.xml goes in. – Ram Mar 29 '13 at 02:48
44

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

Ankur jain
  • 963
  • 3
  • 14
  • 21
23

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>
Beatty
  • 456
  • 3
  • 10
21

The value of my webXml tag needed to look like this in order to work:

<webXml>${project.basedir}\src\main\webapp\WEB-INF\web.xml</webXml> 
BoneGoat
  • 554
  • 5
  • 9
  • exactly! Couldn't figure it out until I saw I had just a slash at the beginning `\src\main\webapp` doesn't work! Not in v2.6 – Adam Feb 25 '16 at 19:38
20

I had the exact same problem and i solved it like this :

Make a new folder named WEB-INF under src/main/webbapp then

Right Click on your Project -> Java EE Tools -> Generate Deployment Descriptor Stub

This should generate your web.xml

I hope this helps by solving your problem :D

Catalin Ciolocoiu
  • 542
  • 1
  • 6
  • 15
13

It does look like you have web.xml in the right location, but even so, this error is often caused by the directory structure not matching what Maven expects to see. For example, if you start out with an Eclipse webapp that you are trying to build with Maven.

If that is the issue, a quick fix is to create a
src/main/java and a
src/main/webapp directory (and other directories if you need them) and just move your files.

Here is an overview of the maven directory layout: http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html

Johan
  • 74,508
  • 24
  • 191
  • 319
MattC
  • 5,874
  • 1
  • 47
  • 40
12

failOnMissingWebXml since 2020

All other answers about might be obsolete because the default value used by the maven-war-plugin changed:

Starting with 3.0.1, this property defaults to false if the project depends on the Servlet 3.0 API or newer.

So the ONLY thing you have to do is to add

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.0.1</version>
</dependency>

Example:

<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>
    <groupId>foo</groupId>
    <artifactId>bar</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
        </dependency>
    </dependencies>
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>3.3.2</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>
Grim
  • 1,938
  • 10
  • 56
  • 123
10

As per the documentation, it says : Whether or not to fail the build if the web.xml file is missing. Set to false if you want you WAR built without a web.xml file. This may be useful if you are building an overlay that has no web.xml file. Default value is: true. User property is: failOnMissingWebXml.

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

Hope it makes more clear

Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
9

It worked for me too.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <webXml>WebContent\WEB-INF\web.xml</webXml>
    </configuration>
</plugin>
Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
Vineet kaushik
  • 351
  • 3
  • 4
8

This is an old question, and there are many answers, most of which will be more or less helpful; however, there is one, very important and still relevant point, which none of the answers touch (providing, instead, different hacks to make build possible), and which, I think, in no way has a less importance.. on the contrary.

According to your log message, you are using Maven, which is a Project Management tool, firmly following the conventions, over configuration principle.

When Maven builds the project:

  1. it expects your project to have a particular directory structure, so that it knows where to expect what. This is called a Maven's Standard Directory Layout;
  2. during the build, it creates also proper directory structure and places files into corresponding locations/directories, and this, in compliance with the Sun Microsystems Directory Structure Standard for Java EE [web] applications.

You may incorporate many things, including maven plugins, changing/reconfiguring project root directory, etc., but better and easier is to follow the default conventions over configuration, according to which, (now is the answer to your problem) there is one simple step that can make your project work: Just place your web.xml under src\main\webapp\WEB-INF\ and try to build the project with mvn package.

Giorgi Tsiklauri
  • 9,715
  • 8
  • 45
  • 66
6

If you change the default project path, you must specify the location of the web.xml file, for example:

        <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>
johnander11
  • 99
  • 1
  • 6
5

mvn-war-plugin 2.3 fixes this:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
        </plugin>
        ...
gabor
  • 400
  • 3
  • 12
5

I have had the same error on the test server but not in local. After a few minutes, I discovered that the IDE wasn't synchronized with the pom.xml. Here is how I solve it:

Re-Generate the deployment descriptor with Eclipse

  1. Right click on your project folder
  2. In the contextual menu, choose "Java EE Tools" then "Generate Deployment Descriptor Stub" Generate web.xml
  3. It will create the web.xml. web.xml in project structure

Re-Generate the deployment descriptor with IntelliJ

  1. Right click on your project folder
  2. In the contextual menu, choose "Open Module Settings", then click on the + to add the web deployment descriptor. Generate the deployment descriptor
  3. Then your can change the path to your descriptor or the Web Ressource Directoriesand the on the right side.
  4. Then you will get something like: Project structure
KeyMaker00
  • 6,194
  • 2
  • 50
  • 49
  • 1
    and in netbeans you would: right click the project node> New > Other > Web > Standard Deployment Descriptor (web.xml). – shabby Nov 23 '16 at 07:37
2

Make sure pom.xml is placed properly in Project folder. and not inside target folder or any where else.

Looks like pom.xml is not relatively aligned.

Meghashyam
  • 21
  • 1
2

Was your folder structure altered so the file is no-longer at /src/main/webapp/WEB-INF/web.xml ?

To resolve this issue, I gave my web folder the name webapp and placed it inside the src/main. Maven seems to look for web.xml by default at /src/main/webapp/WEB-INF/web.xml. If you do this then you don't need to explicitly tell maven where web.xml is. And if you've altered your folder structure and your build recently stopped working, this could be why.

Note: This is an old post but the posted solutions don't point out why a working build would suddenly stop working.

Usman Mutawakil
  • 4,993
  • 9
  • 43
  • 80
2

This error occurs because you tell to Maven to pakage files to war.

<packaging>war</packaging>

Do you really need war? If not, put jar there. Here is full code:

<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>
Giorgi Tsiklauri
  • 9,715
  • 8
  • 45
  • 66
Yuliia Ashomok
  • 8,336
  • 2
  • 60
  • 69
  • 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. – Giorgi Tsiklauri Mar 13 '19 at 15:39
1

I encountered this message while trying to package a Spring Boot project as a WAR file and deploying that WAR file in a standalone Tomcat instance.

I used Spring Intializr to generate the initial pom.xml and related artifacts. The problem was that in that pom.xml (Spring version 2.6.+), this dependency was in place.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-webflux</artifactId>
</dependency>

I had to replace it with this one:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

And also added this dependency with scope of "provided"

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>

Also, of course, changed the packaging

<packaging>war</packaging>
George Smith
  • 438
  • 4
  • 8
0

Make sure to run mvn install before you compile your war.

Mahmoud
  • 9,729
  • 1
  • 36
  • 47
0

There are two things to note regarding packaging.

  1. Packaging to a war file will require you define the web.xml file in the appropriate folder as described by Catalin Ciolocoiu.
  2. But changing the package type to jar would not need that structure and should work straight away.
Takashi
  • 11
  • 2
0

If you don't want to use web.xml you exclude it in pom.xml.

<build>
<plugins>
    
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.6</version>
        <configuration>
            <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
    </plugin>
    
</plugins>
</build>

The right version you see in the error message:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war 
(default-war) on project spring4-mvc-maven-ajax-example: 

Here it is 2.2.

Found this solution on mycong.com

https://mkyong.com/maven/maven-webxml-attribute-is-required/

Andreas L.
  • 2,805
  • 23
  • 23