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:
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
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:
Please pay attention to the version of the maven-war-plugin
, it must
be 3.0.0+
, or else you must add as follows:
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!