Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven can't find web.xml

I'm getting the following error when building my maven-project with the command mvn clean install

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war
(default-war) on project MyProject:
Error assembling WAR: webxml attribute is required (or pre-existing 
WEB-INF/web.xml if executing in update mode)

I do have web.xml in the project. In the folder web/WEB-INF/web.xml

I am using IntelliJ IDEA. I can avoid this problem by adding the following to pom.xml:

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

But I'd like to know why maven claims that web.xml is missing even though it's not and it is in the default location when creating a new web application project in IntelliJ IDEA.

like image 722
Steve Waters Avatar asked Apr 19 '16 18:04

Steve Waters


People also ask

Where is WEB xml Maven project?

In particular, note that the web. xml file is stored at ProjectDir/src/main/webapp/WEB-INF/web. xml .

How do I fix a WEB xml error?

The other solution is, click on your project > right-click > Java EE Tools > Generate Deployment Descriptor Stub as shown in the below image. And this will generate the web. xml file inside the WEB-INF folder with some pre-defined code as shown in the below image. And it will also resolve the error.

Why WEB xml is not created in Eclipse?

Eclipse allows you to NOT create a web. xml file when you create Dynamic Web Project for Java EE 6, since the Java EE 6 spec (in general) and Servlet 3.0 spec (in particular) attempt to de-emphasize deployment descriptors. You can use annotation to provide all the data that had been included in the web. xml file.


1 Answers

Your problem is that you have web.xml in this path: web/WEB-INF/web.xml

With Maven, the web.xml should go in src/main/webapp/WEB-INF or you should change the webXml configuration of the war plugin (see here: https://maven.apache.org/plugins/maven-war-plugin/war-mojo.html#webXml)

like image 166
mikeb Avatar answered Oct 05 '22 17:10

mikeb