Maven中的“webxml属性是必需的”错误

    技术2022-07-13  89

    本文翻译自:“webxml attribute is required” error in Maven

    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) 装配WAR时出错:需要webxml属性(如果在更新模式下执行,则为预先存在的WEB-INF / web.xml)

    I have got web.xml in right place which is projectname\\src\\main\\webapp\\WEB-INF\\web.xml 我有正确的web.xml ,它是projectname\\src\\main\\webapp\\WEB-INF\\web.xml

    What could be causing this? 可能是什么导致了这个?


    #1楼

    参考:https://stackoom.com/question/MSHk/Maven中的-webxml属性是必需的-错误


    #2楼

    It works perfectly for me too. 它也适合我。

    <project> ..... <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <webXml>WebContent\WEB-INF\web.xml</webXml> </configuration> </plugin> </plugins> </build> </project>

    #3楼

    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. 它确实看起来像你在正确的位置有web.xml,但即便如此,这个错误通常是由于目录结构与Maven期望看到的不匹配。 For example, if you start out with an Eclipse webapp that you are trying to build with Maven. 例如,如果您开始使用您尝试使用Maven构建的Eclipse Web应用程序。

    If that is the issue, a quick fix is to create a 如果这是问题,快速解决方法是创建一个 src/main/java and a src/main/java和a src/main/webapp directory (and other directories if you need them) and just move your files. src/main/webapp目录(以及其他目录,如果您需要它们)并只移动您的文件。

    Here is an overview of the maven directory layout: http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html 以下是maven目录布局的概述: http : //maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html


    #4楼

    我的webXml标记的值需要看起来像这样才能工作:

    <webXml>${project.basedir}\src\main\webapp\WEB-INF\web.xml</webXml>

    #5楼

    Make sure pom.xml is placed properly in Project folder. 确保将pom.xml正确放置在Project文件夹中。 and not inside target folder or any where else. 而不是在目标文件夹或其他任何地方。

    Looks like pom.xml is not relatively aligned. 看起来pom.xml没有相对对齐。


    #6楼

    mvn-war-plugin 2.3 fixes this: mvn-war-plugin 2.3解决了这个问题:

    <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.3</version> </plugin> ...
    Processed: 0.027, SQL: 9