Skip to content

maven

1 post with the tag “maven”

How to solve Error assembling WAR webxml attribute is required exception when building spring boot wars

1. The purpose of this post

When build springboot app as war file, sometime we encounter this exception:

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

The error shows that :

  • it needs a webxml attribute to construct the WAR file
  • Or you should provide a WEB-INF/web.xml to build the WAR file

2. Environments

  • spring boot 1.x and 2.x

3. The solution

3.1 The original pom.xml

Before solve , we can look at the original pom.xml

pom.xml
<build>
<finalName>${artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>exec</classifier>
</configuration>
</execution>
</executions>
</plugin>
</build>

We use the spring-boot-maven-plugin to execute the goal repackage with exec classifier.

The classifier, which uses exec here, indicating that the generated jar file will have a -EXEC suffix.

In summary, this configuration uses spring-boot-maven-plugin plug-in to reintegrate the project and generate a executable jar file with the -EXEC suffix.

But, we want to WAR file to be generated, not a executable jar file!

So , we need to change the pom.xml to generate a WAR.

3.2 The right pom.xml

We should add maven-war-plugin to build springboot as a WAR file:

pom.xml
<build>
<finalName>${artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>exec</classifier>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</build>

Please pay attention to the version of the maven-war-plugin, it must be 3.0.0+, or else you must add as follows:

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

Hope it helps for you.

Final Words + More Resources

My intention with this article was to help others who might be considering solving such problem. So I hope that’s been the case here. If you still have any questions, don’t hesitate to ask me by email: [email protected].

Here are also the most important links from this article along with some further resources that will help you in this scope:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!