webxml attribute is required with Servlet 3.0

Solution 1:

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:

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

<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>
  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:

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.