6

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.
  • 7,816
  • 20
  • 80
  • 154
  • 1
    I believe this is a duplicate: please look at these two links: [Maven - Solved - web.xml not found in Java EE7 project](http://stackoverflow.com/questions/31413990/solved-web-xml-not-found-in-java-ee7-project), and [Eclipse - web.xml is missing](http://stackoverflow.com/questions/31835033/web-xml-is-missing-and-failonmissingwebxml-is-set-to-true) – paulsm4 Nov 04 '15 at 19:15
  • Can you please provide the full `pom.xml`? – Avihoo Mamka Nov 05 '15 at 09:35
  • Both of those suggested answers didn't solve my problem. Deleting .metada .project .settings .classpath. caused more errors in addition to this. The full `pom.xml` is now attached. I tried updating the project in Eclipse but no difference. – Peter G. Nov 05 '15 at 10:06
  • 1
    It's actually the _question_ (not answer) from the (first) link that has the solution. Add the `maven-war-plugin` to your pom, inside the `{here}` – Paul Samsotha Nov 05 '15 at 10:47

5 Answers5

19

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.

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
  • 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) – Peter G. Nov 05 '15 at 15:20
10
  1. Do:

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

    <packaging>war</packaging>
    <properties>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </properties>
    
Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
question_maven_com
  • 2,457
  • 16
  • 21
2

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.

1

Add the below property to POM.xml

 <failOnMissingWebXml>false</failOnMissingWebXml>
0

I was able to resolve this problem by adding this property in POM.xml as like below.

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