'"webxml attribute is required" error in Maven
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?
Solution 1:[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:[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:[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:[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:[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>
Solution 6:[6]
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>
Solution 7:[7]
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
Solution 8:[8]
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 asrc/main/java and asrc/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
Solution 9:[9]
? failOnMissingWebXml since 2020
All other answers about might be obsolete because the default value used by the maven-war-plugin changed:
Starting with 3.1.0, 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.1.0</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>
<properties>
<tomcat.ignorePackaging>true</tomcat.ignorePackaging>
</properties>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.1.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Solution 10:[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
Solution 11:[11]
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>
Solution 12:[12]
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:
- 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; - 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 Standardfor 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.
Solution 13:[13]
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>
Solution 14:[14]
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>
...
Solution 15:[15]
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
- Right click on your project folder
- In the contextual menu, choose "Java EE Tools" then "Generate Deployment Descriptor Stub"

- It will create the web.xml.

Re-Generate the deployment descriptor with IntelliJ
Solution 16:[16]
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.
Solution 17:[17]
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.
Solution 18:[18]
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>
Solution 19:[19]
Make sure to run mvn install before you compile your war.
Solution 20:[20]
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>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow


