Maven – webxml attribute is required with Servlet 3.0

mavenmaven-pluginvaadinvaadin7

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?

Best Answer

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.