"webxml attribute is required" error in Maven

MavenWar

Maven Problem Overview


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?

Maven Solutions


Solution 1 - Maven

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

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

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

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

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

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

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

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

Solution 9 - Maven

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

 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 11 - Maven

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

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.

Solution 13 - Maven

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

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

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

Solution 16 - Maven

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

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

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

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

Solution 20 - Maven

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>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser617966View Question on Stackoverflow
Solution 1 - MavenArpitView Answer on Stackoverflow
Solution 2 - MavenSagarView Answer on Stackoverflow
Solution 3 - MavenBurhan ARASView Answer on Stackoverflow
Solution 4 - MavenAnkur jainView Answer on Stackoverflow
Solution 5 - MavenBeattyView Answer on Stackoverflow
Solution 6 - MavenBoneGoatView Answer on Stackoverflow
Solution 7 - MavenCatalin CiolocoiuView Answer on Stackoverflow
Solution 8 - MavenMattCView Answer on Stackoverflow
Solution 9 - MavencodechefvaibhavkashyapView Answer on Stackoverflow
Solution 10 - MavenGrimView Answer on Stackoverflow
Solution 11 - MavenVineet kaushikView Answer on Stackoverflow
Solution 12 - MavenGiorgi TsiklauriView Answer on Stackoverflow
Solution 13 - Mavenjohnander11View Answer on Stackoverflow
Solution 14 - MavengaborView Answer on Stackoverflow
Solution 15 - MavenKeyMaker00View Answer on Stackoverflow
Solution 16 - MavenMeghashyamView Answer on Stackoverflow
Solution 17 - MavenUsman MutawakilView Answer on Stackoverflow
Solution 18 - MavenYuliia AshomokView Answer on Stackoverflow
Solution 19 - MavenMahmoud K.View Answer on Stackoverflow
Solution 20 - MavenGeorge SmithView Answer on Stackoverflow