web.xml is missing and <failOnMissingWebXml> is set to true

Yogesh Doke picture Yogesh Doke · Aug 5, 2015 · Viewed 248.3k times · Source

Consider:

Enter image description here

When I create a simple Maven project in Eclipse I am getting this error:

web.xml is missing and <failOnMissingWebXml> is set to true

How can I fix this problem?

Answer

Martijn Burger picture Martijn Burger · Nov 11, 2015

This is a maven error. It says that it is expecting a web.xml file in your project because it is a web application, as indicated by <packaging>war</packaging>. However, for recent web applications a web.xml file is totally optional. Maven needs to catch up to this convention. Add this to your maven pom.xml to let maven catch up and you don't need to add a useless web.xml to your project:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
    </plugins>
</build>

This is a better solution than adding an empty web.xml because this way your final product stays clean, your are just changing your build parameters.

For more current versions of maven you can also use the shorter version:

<properties>
    <failOnMissingWebXml>false</failOnMissingWebXml>
</properties>