Maven can't find web.xml
Asked Answered
P

1

5

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.

Potage answered 19/4, 2016 at 18:46 Comment(3)
The path web/WEB-INF/web.xml is not the default because there shouldn't be a web dir between WEB-INF/web.xml and the project root dir unless the project root dir is named 'web'.Cloyd
Moved WEB-INF out of web-folder to project root and still getting the same error.Potage
is your web.xml in src/main/webapp/WEB-INF?Tracey
R
12

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)

Returnee answered 12/4, 2017 at 14:4 Comment(2)
In my case, I actually have web.xml in ./src/main/webapp/WEB-INF, but it doesn't run properly with mvn jetty:run, I'm not really sure why, it always says it that the directory doesn't exist.Swamp
Post your full pom file. You have it in the right place unless you're overriding somethingReturnee

© 2022 - 2024 — McMap. All rights reserved.