Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FailOnMissingWebXml error when validating pom.xml in Eclipse

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.

like image 699
Peter G. Avatar asked Nov 04 '15 19:11

Peter G.


2 Answers

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.

like image 150
Paul Samsotha Avatar answered Sep 25 '22 10:09

Paul Samsotha


  1. Do:

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

    <packaging>war</packaging>
    <properties>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </properties>
    
like image 31
question_maven_com Avatar answered Sep 25 '22 10:09

question_maven_com