webxml attribute is required with Servlet 3.0

MavenMaven PluginVaadinVaadin7

Maven Problem Overview


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?

Maven Solutions


Solution 1 - Maven

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.

Solution 2 - Maven

I landed here with a similar error but using Eclise Luna (4.4) with Maven 3.0

I ended up doing this:

  1. move the WebContent\WEB-INF\web.xml to src\main\webapp\WEB-INF\web.xml

  2. Use the <webXml> to specify the location of web.xml

> > > > org.apache.maven.plugins > maven-compiler-plugin > 3.0 > > src\main\webapp\WEB-INF\web.xml > > > > > ${project.artifactId} >

  1. Run mvn package and see a BUILD SUCCESS (for WAR)

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

Solution 3 - Maven

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.

Solution 4 - Maven

Could be that you are not following the standard maven directory layout as described here Maven directory layout

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
QuestionRogerView Question on Stackoverflow
Solution 1 - MavenSergey MakarovView Answer on Stackoverflow
Solution 2 - MavenMauricio Gracia GutierrezView Answer on Stackoverflow
Solution 3 - MavensiegiView Answer on Stackoverflow
Solution 4 - MavenACVView Answer on Stackoverflow