在 Eclipse 中验证 pom.xml 时出现 FailOnMissingWebXml 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33530105/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:36:04  来源:igfitidea点击:

FailOnMissingWebXml error when validating pom.xml in Eclipse

eclipsemavenjakarta-eewarpom.xml

提问by Peter G.

When compiling a Maven project I get this error during validation phase of the pom.xml. It is quite a large project with complex build process. The project contains only JavaScript code and does not have to be compiled into war. I'm looking for a way to either:

编译 Maven 项目时,我在pom.xml. 这是一个相当大的项目,具有复杂的构建过程。该项目仅包含 JavaScript 代码,不必编译为war. 我正在寻找一种方法:

  • Just disable the error through disabling failOnMissingWebXml(it appears to be a non-critical Eclipse error)
  • Find a solution that prevents this validation error in Eclipse (answers to related questions didn't work for my specific scenario)
  • 只需通过禁用来禁用错误failOnMissingWebXml(这似乎是一个非关键的 Eclipse 错误)
  • 在 Eclipse 中找到防止此验证错误的解决方案(相关问题的答案不适用于我的特定场景)

The full error:

完整的错误:

Description Resource    Path    Location    Type web.xml is missing 
and <failOnMissingWebXml> is set to true    pom.xml /testproject    line 6    
Maven Java EE Configuration Problem

After clicking on the error the problem seems to be on this line of pom.xml:

单击错误后,问题似乎出在以下行上pom.xml

  <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>
  <groupId>com.scs</groupId>
  <artifactId>scs-control-panel</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging> **THE ERROR POINTS TO THIS LINE**

  <parent>
    <groupId>com.scs</groupId>
    <artifactId>scs</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>../scs</relativePath>
  </parent>

  <build>
  </build>

  <dependencies>
  </dependencies>

</project>

Not sure if this is an Eclipse or Maven error, but probably Eclipse, since Maven runs smoothly through command line. It may also be a bug in Eclipse, I'm running Eclipse Java EE IDE for Web Developers Version: Mars.1 Release (4.5.1).

不确定这是 Eclipse 还是 Maven 错误,但可能是 Eclipse,因为 Maven 通过命令行顺利运行。这也可能是 Eclipse 中的一个错误,我正在运行 Eclipse Java EE IDE for Web Developers 版本:Mars.1 Release (4.5.1)。

UPDATE1: I tried updating the project in Eclipse but no difference.

UPDATE1:我尝试在 Eclipse 中更新项目,但没有区别。

UPDATE2: I tried changing the package type from warto pombut no difference.

UPDATE2:我尝试将包类型从 更改为warpom但没有区别。

回答by Paul Samsotha

Everything in Maven revolves around plugins. Plugins are the programs that execute some behavior within the build process. Some plugin inclusions are implied without us having to declare anything.

Maven 中的一切都围绕着插件。插件是在构建过程中执行某些行为的程序。某些插件包含是隐含的,我们无需声明任何内容。

These implied have default configurations. For example, the maven-compiler-pluginis included in all projects, without having to declare it. To override the default configurations, we need to declare the plugin in out pom.xml file and set the configurations. For example you will see a lot of projects override the default on the maven-compiler-pluginwhich has it's sourceand targetset to Java 1.5. We can change to 1.8

这些隐含的具有默认配置。例如,maven-compiler-plugin包含在所有项目中,无需声明。要覆盖默认配置,我们需要在 pom.xml 文件中声明插件并设置配置。例如,你会看到很多的项目覆盖的默认maven-compiler-plugin它有它的sourcetarget集到Java 1.5。我们可以改成1.8

<build>
  <plugins>
      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.1</version>
          <configuration>
              <source>1.8</source>
              <target>1.8</target>
          </configuration>
      </plugin>
  </plugins>
</build>

This is just some theory behind the plugins to give you an idea of what's going on.

这只是插件背后的一些理论,让您了解正在发生的事情。

With that being said, in order to use <packaging>war<packaging>, the maven-war-pluginis used without us having to declare anything. Just like when using <packaging>jar</packaging>, the maven-jar-plugin's inclusion is implied.

话虽如此,为了使用<packaging>war<packaging>maven-war-plugin无需我们声明任何内容即可使用。就像使用时一样<packaging>jar</packaging>maven-jar-plugin的包含是隐含的。

The default configuration for the maven-war-pluginis the fail where there is no web.xml(that configuration property being failOnMissingWebXml). So if we want to override this default, we need to declare the plugin, then set the value for the property to false (not fail)

的默认配置maven-war-plugin是失败的地方没有web.xml(该配置属性是failOnMissingWebXml)。所以如果我们想覆盖这个默认值,我们需要声明插件,然后将属性的值设置为false(不会失败)

<build>
    <plugins>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>    
            </configuration>
        </plugin>
    </plugins>
</build>


UPDATE

更新

The compiler plugin now allows you to just use a property that it will lookup. This allows you to simply declare the property without having to override the plugin. To add this property, you would simply add the property failOnMissingWebXmlwith a value of false to the project <properties>

编译器插件现在允许您只使用它将查找的属性。这允许您简单地声明属性而不必覆盖插件。要添加此属性,您只需将failOnMissingWebXml值为 false的属性添加到项目中<properties>

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

Just by adding this, if you have no further configurations you need to add to the compiler plugin, you will no longer have to override and declare the compiler plugin in your pom.

只需添加这个,如果你没有进一步的配置需要添加到编译器插件中,你将不再需要在你的 pom.xml 中覆盖和声明编译器插件。

回答by question_maven_com

  1. Do:

    mvn clean eclipse:clean
    
  2. Add this to your POM:

    <packaging>war</packaging>
    <properties>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </properties>
    
  1. 做:

    mvn clean eclipse:clean
    
  2. 将此添加到您的 POM:

    <packaging>war</packaging>
    <properties>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </properties>
    

回答by VYSAKHAN SREEKUMARAN KASTHURI

Add the below property to POM.xml

将以下属性添加到 POM.xml

 <failOnMissingWebXml>false</failOnMissingWebXml>

回答by Michael Hübener

I guess the easiest path is to choose the war plugin version 3. The defaultvalue for failOnMissingWebXml has been changed from trueto false.

我想最简单的方法是选择 war 插件版本3。failOnMissingWebXml的默认值已从true更改为false

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.0.0</version>
</plugin>

Once set in your pom the nasty error vanishes for ever.

一旦在你的 pom 中设置,讨厌的错误就会永远消失。

回答by Ragu Venkatesan

I was able to resolve this problem by adding this property in POM.xml as like below.

我能够通过在 POM.xml 中添加这个属性来解决这个问题,如下所示。

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