Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven Error assembling WAR: webxml attribute is required when building the SpringMVC project with pure Java Based Configuration and no xml's

I am developing a Spring MVC project with pure Java based configuration. I am getting the error below when I do a Maven clean install.

Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project SpringMVC-ShoppingCart: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]

The error says that web.xml is missing, but I did not have one since I used pure Java based configuration.

How to make sure that the project builds and creates war file without web.xml?

like image 673
Omkar Puttagunta Avatar asked Oct 28 '15 11:10

Omkar Puttagunta


2 Answers

This error happens because the maven-war-plugin, in version 2.6 or lower, expects by default a src/main/webapp/web.xml file to be present in your WAR project, and it didn't find it.

Use annotations and upgrade to 3.0.0 or newer

As of version 3.0.0 of the plugin, the presence of a web.xml is not mandatory by default anymore:

The default value for failOnMissingWebXml has been changed from true to false.

This means that upgrading the plugin directly solves the issue. You can add the following configuration in your POM:

<plugin>
  <artifactId>maven-war-plugin</artifactId>
  <version>3.0.0</version>
</plugin>

The reason is that since Servlet 3.0, the web.xml file is no longer needed in a web application, and can be replaced with annotations to have a Java-based configuration (MWAR-262). However, since your project might not use annotations to replace this file, in which case the web.xml could actually be missing, a sanity check was added in version 3.0.1 of the plugin to make sure that the annotation @WebServlet is in the compile classpath of your WAR project (MWAR-396). If it isn't, and there is no web.xml file in your project, the plugin will still fail by default.

Ignore the missing web.xml

If you just want the plugin to explicitly ignore a missing web.xml file, regardless of the usage of annotations, you can set the failOnMissingWebXml parameter to false. A sample configuration would be:

<plugin>
  <artifactId>maven-war-plugin</artifactId>
  <version>2.6</version>
  <configuration>
    <failOnMissingWebXml>false</failOnMissingWebXml>
  </configuration>
</plugin>
like image 56
Tunaki Avatar answered Nov 16 '22 12:11

Tunaki


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

like image 42
Ankur jain Avatar answered Nov 16 '22 14:11

Ankur jain