I get this error when trying to compile a Vaadin WAR:
Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project testvaadin-web: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]
I know this error means that maven cannot find my web.xml, but in the "Book of Vaadin" it says that web.xml is not needed when using Servlet API 3.0 and the Annotation @WebServlet
in your UI class.
I am compiling my widgetsets in a separate profile (according to this guide) and it compiles fine when I rnu this profile. However, when I compile only the web-project, I get above mentioned error.
What gives?
Do I override the maven behaviour somehow? Vaadin didn't even create a WEB-INF directory. I guess I could create WEB-INF folder and keep a "ghost" web.xml in there to keep maven happy, but that doesn't seem right.
Am I missing something?
Does anyone know a good solution to this?
Now, once we execute the mvn install command, the WAR file will be generated inside the target folder. Using the mvn:war:exploded command, we can generate the exploded WAR as a directory inside the target directory.
Specifies where to find the web. xml file in the current Maven project, relative to the location of pom. xml . The default is src/main/webapp/WEB-INF/web.
The WAR Plugin is responsible for collecting all artifact dependencies, classes and resources of the web application and packaging them into a web application archive.
By default maven-war-plugin will fail if it can't find web.xml, see here. If you are creating Maven project using latest archetype, you will get this parameter set to false:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
If you want to use web.xml instead of annotations, just create WEB-INF/web.xml and define servlet there, see Book of Vaadin for detailed instruction.
I landed here with a similar error but using Eclise Luna (4.4) with Maven 3.0
I ended up doing this:
move the WebContent\WEB-INF\web.xml to src\main\webapp\WEB-INF\web.xml
Use the <webXml>
to specify the location of web.xml
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.0</version> <configuration> <webXml>src\main\webapp\WEB-INF\web.xml</webXml> </configuration> </plugin> </plugins> <!-- we dont want the version to be part of the generated war file name --> <finalName>${project.artifactId}</finalName> </build>
Before this I tried using the original path of the web.xml file
<webXml>WebContent\WEB-INF\web.xml</webXml>
But maven did not pickit up and is best to follow the maven folder structure
http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html
Since version 3.0.0 the maven-war-plugin
works out of the box with no web.xml
.
Up to at least Maven version 3.3.9 the packaging war
binds to a older version of the maven-war-plugin
, so you need to explicitly set the version in your pom.xml
:
<project>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</build>
</project>
Earlier versions of the maven-war-plugin
had the parameter failOnMissingWebXml
set to true
by default, what causes your problem. See Sergey Makarovs answer on how to manually set the parameter to false
if you need to use a older version of the plugin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With