Spring MVC Tutorial

Core Spring MVC

Spring MVC - Annotation

Spring MVC - Form Handling

Spring MVC with JSTL

Spring MVC with REST API

Spring MVC with Database

How to Resolve WEB xml is missing and failOnMissingWebXml is set to true in Eclipse/STS?

The error message "WEB xml is missing and failOnMissingWebXml is set to true" typically occurs when you're building a Maven-based web project using an older webapp archetype, and your project is missing the web.xml file in the WEB-INF directory. However, in modern Servlet 3.0+ based applications, the web.xml file is no longer mandatory.

Here's how you can resolve this error in Eclipse or Spring Tool Suite (STS):

1. Add a web.xml file (Traditional way):

If you believe that you really need a web.xml file:

  1. Right-click on your project in Eclipse/STS and navigate to New -> Other.
  2. From the wizard, choose General -> File.
  3. Set the folder to src/main/webapp/WEB-INF/ and the file name to web.xml.
  4. Click "Finish".
  5. Populate your web.xml with the necessary content.

2. Update the maven-war-plugin Configuration (Modern way):

If you don't want or need a web.xml:

  1. Open your project's pom.xml file.
  2. Add or update the maven-war-plugin configuration to include the failOnMissingWebXml setting:
<build>
    <plugins>
        ...
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.3.1</version> <!-- Use the latest version here -->
            <configuration>
                <!-- Ignore the missing web.xml file -->
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        ...
    </plugins>
</build>
  1. Save the pom.xml.
  2. Right-click on your project in Eclipse/STS, and choose Maven -> Update Project.

Now, when you build your project, Maven should not complain about the missing web.xml file.

Note:

If you're using a modern version of Spring Boot, you generally don't need a web.xml file. Spring Boot applications are typically configured using Java config and annotations. The maven-war-plugin configuration method is preferred in this case.