webxml attribute is required with Servlet 3.0
Asked Answered
A

4

50

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?

Abstractionist answered 12/8, 2013 at 12:7 Comment(0)
R
109

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.

Rachele answered 12/8, 2013 at 12:24 Comment(4)
I just found it. =) I actually had failOnMissingWebXml in the widget compilation. ThanksAbstractionist
I needed to add the <version>2.4</version> to the plugin to get rid of all my warnings.Friend
Note that you can do this a little more succinctly just by adding <failOnMissingWebXml>false</failOnMissingWebXml> to your <properties> sectionIngenious
just included code snippet in web.xml from the above code snippet as suggested by @Sergey Makarov, it solved the problem. Thanks a lot. Saved 20 minutes there. <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin>Cordeelia
S
3

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

Snailpaced answered 3/6, 2015 at 17:4 Comment(1)
I guess this solution may be really nice if you actually do need to use web.xml in some other part of the same project.Abstractionist
U
1

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.

Undertake answered 22/10, 2016 at 16:9 Comment(0)
D
0

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

Deficient answered 28/5, 2015 at 7:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.