FailOnMissingWebXml error when validating pom.xml in Eclipse

40,179

Solution 1

Everything in Maven revolves around plugins. Plugins are the programs that execute some behavior within the build process. Some plugin inclusions are implied without us having to declare anything.

These implied plugins have default configurations. For example, the maven-compiler-plugin is included in all projects without having to declare it. To override the default configurations we need to declare the plugin in our pom.xml file and set the configurations. For instance, you will see a lot of projects override the default version on the maven-compiler-plugin which has it's source and target set to Java 1.5. We can change to 1.8

<build>
  <plugins>
      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.1</version>
          <configuration>
              <source>1.8</source>
              <target>1.8</target>
          </configuration>
      </plugin>
  </plugins>
</build>

This is just some theory behind the plugins to give you an idea of what's going on.

With that being said, in order to use <packaging>war<packaging>, the maven-war-plugin is used without us having to declare anything. Just like when using <packaging>jar</packaging>, the maven-jar-plugin's inclusion is implied.

The default configuration for the maven-war-plugin is to fail where there is no web.xml (that configuration property being failOnMissingWebXml). So if we want to override this default, we need to declare the plugin, then set the value for the property to false (not fail)

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

UPDATE

The war plugin now allows you to just use a property that it will lookup. This allows you to simply declare the property without having to override the plugin. To add this property, you would simply add the property failOnMissingWebXml with a value of false to the project <properties>

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

Just by adding this, if you have no further configurations you need to add to the compiler plugin, you will no longer have to override and declare the compiler plugin in your pom.


UPDATE 2

So if you declare the maven-war-plugin and use a <version> 3.0.0+, the default for no web.xml failure will be set to false, so we no longer have to override the configuration property, though we still need to declare the plugin.

Solution 2

  1. Do:

    mvn clean eclipse:clean
    
  2. Add this to your POM:

    <packaging>war</packaging>
    <properties>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </properties>
    

Solution 3

I guess the easiest path is to choose the war plugin version 3. The default value for failOnMissingWebXml has been changed from true to false.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.0.0</version>
</plugin>

Once set in your pom the nasty error vanishes for ever.

Solution 4

Add the below property to POM.xml

 <failOnMissingWebXml>false</failOnMissingWebXml>
Share:
40,179
Peter G.
Author by

Peter G.

My profile is that of a software product owner with a strong engineering background. I like building end-to-end solutions that typically require a mix of technical skills, business skills, and mathematical knowledge. I understand how to optimize data algorithms, and how to explain my findings. My technical background allows me to deal with data at scale. I'm an active learner with a strong aptitude towards technology and discovering the new. My areas of expertise are Mobile and Data Analytics. I have a niche for data-driven apps. That area poses a set of new challenges and opportunities and also it is one of the most rapidly growing fields.

Updated on July 09, 2022

Comments

  • Peter G.
    Peter G. almost 2 years

    When compiling a Maven project I get this error during validation phase of the pom.xml. It is quite a large project with complex build process. The project contains only JavaScript code and does not have to be compiled into war. I'm looking for a way to either:

    • Just disable the error through disabling failOnMissingWebXml (it appears to be a non-critical Eclipse error)
    • Find a solution that prevents this validation error in Eclipse (answers to related questions didn't work for my specific scenario)

    The full error:

    Description Resource    Path    Location    Type web.xml is missing 
    and <failOnMissingWebXml> is set to true    pom.xml /testproject    line 6    
    Maven Java EE Configuration Problem
    

    After clicking on the error the problem seems to be on this line of pom.xml:

      <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.scs</groupId>
      <artifactId>scs-control-panel</artifactId>
      <version>1.0-SNAPSHOT</version>
      <packaging>war</packaging> **THE ERROR POINTS TO THIS LINE**
    
      <parent>
        <groupId>com.scs</groupId>
        <artifactId>scs</artifactId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>../scs</relativePath>
      </parent>
    
      <build>
      </build>
    
      <dependencies>
      </dependencies>
    
    </project>
    

    Not sure if this is an Eclipse or Maven error, but probably Eclipse, since Maven runs smoothly through command line. It may also be a bug in Eclipse, I'm running Eclipse Java EE IDE for Web Developers Version: Mars.1 Release (4.5.1).

    UPDATE1: I tried updating the project in Eclipse but no difference.

    UPDATE2: I tried changing the package type from war to pom but no difference.

  • Peter G.
    Peter G. over 8 years
    That seems to solve the problem - I have to check your answer again. This may also be an issue with the newest version of Eclipse (Mars) as the check doesn't seem to result in an error in the older version (Luna)