“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条回答
别忘想泡老子
2楼-- · 2019-01-07 02:24

This error occurs because you say Maven to pakage files to war.

<packaging>war</packaging>

Do you really needs war? If not, put jar there. Here is full code:

<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>
    <version>1.0-SNAPSHOT</version>

    <groupId>com.your.groupid</groupId>
    <artifactId>artifactid</artifactId>
    <packaging>jar</packaging>
查看更多
成全新的幸福
3楼-- · 2019-01-07 02:25

This is because you have not included web.xml in your web project and trying to build war using maven. To resolve this error, you need to set the failOnMissingWebXml to false in pom.xml file.

For example:

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

Please see the blog for more details: https://ankurjain26.blogspot.in/2017/05/error-assembling-war-webxml-attribute.html

查看更多
我想做一个坏孩纸
4楼-- · 2019-01-07 02:26
<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </configuration>
</plugin>

This solution works for me(I was using 2.2 before). Also, I am using Java Based Configuration for Servlet 3.0 and no need to have web.xml file.

查看更多
Deceive 欺骗
5楼-- · 2019-01-07 02:26

It does look like you have web.xml in the right location, but even so, this error is often caused by the directory structure not matching what Maven expects to see. For example, if you start out with an Eclipse webapp that you are trying to build with Maven.

If that is the issue, a quick fix is to create a
src/main/java and a
src/main/webapp directory (and other directories if you need them) and just move your files.

Here is an overview of the maven directory layout: http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html

查看更多
劫难
6楼-- · 2019-01-07 02:33

It worked for me too.

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <webXml>WebContent\WEB-INF\web.xml</webXml>
            </configuration>
        </plugin>
查看更多
成全新的幸福
7楼-- · 2019-01-07 02:33

Make sure pom.xml is placed properly in Project folder. and not inside target folder or any where else.

Looks like pom.xml is not relatively aligned.

查看更多
登录 后发表回答