“webxml attribute is required” error in Maven

2019-01-07 02:13发布

I am getting the following error:

Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)

I have got web.xml in right place which is projectname\src\main\webapp\WEB-INF\web.xml

What could be causing this?

标签: maven war
16条回答
Animai°情兽
2楼-- · 2019-01-07 02:33

Was your folder structure altered so the file is no-longer at /src/main/webapp/WEB-INF/web.xml ?

To resolve this issue, I gave my web folder the name webapp and placed it inside the src/main. Maven seems to look for web.xml by default at /src/main/webapp/WEB-INF/web.xml. If you do this then you don't need to explicitly tell maven where web.xml is. And if you've altered your folder structure and your build recently stopped working, this could be why.

Note: This is an old post but the posted solutions don't point out why a working build would suddenly stop working.

查看更多
来,给爷笑一个
3楼-- · 2019-01-07 02:34

If you are migrating from XML-based to Java-based configuration and you have removed the need for web.xml by implementing WebApplicationInitializer, simply remove the requirement for the web.xml file to be present.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <failOnMissingWebXml>false</failOnMissingWebXml>
        ... 
    </configuration>
查看更多
做自己的国王
4楼-- · 2019-01-07 02:35

mvn-war-plugin 2.3 fixes this:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
        </plugin>
        ...
查看更多
放我归山
5楼-- · 2019-01-07 02:39

The value of my webXml tag needed to look like this in order to work:

<webXml>${project.basedir}\src\main\webapp\WEB-INF\web.xml</webXml> 
查看更多
登录 后发表回答