【问题标题】:Why is maven-war-plugin failing for web.xml missing if I configured it not to fail on missing web.xml?如果我将 maven-war-plugin 配置为在缺少 web.xml 时不会失败,为什么缺少 web.xml 会失败?
【发布时间】:2014-06-18 17:02:56
【问题描述】:

这是一个挑战:为什么这个构建失败了?

我已将 Maven 的 maven-war-plugin 配置为不会在缺少的 web.xml 文件上失败,看来:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <executions>
            <execution>
                <id>prepare-war</id>
                <phase>prepare-package</phase>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <archiveClasses>false</archiveClasses>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix />
                        </manifest>
                        <manifestEntries>
                            <Implementation-Build>${build.number}</Implementation-Build>
                            <Implementation-Title>${project.name}</Implementation-Title>
                            <Built-By>${user.name}</Built-By>
                            <Built-OS>${os.name}</Built-OS>
                            <Build-Date>${build.date}</Build-Date>
                        </manifestEntries>
                    </archive>
                    <webResources>
                        <resource>
                            <!-- this is relative to the pom.xml directory -->
                            <directory>./target/dist</directory>
                        </resource>
                    </webResources>
                </configuration>
            </execution>
        </executions>
    </plugin>

但尽管有这种配置,它仍然像这样失败:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.4:war (default-war) on project com.specktro.orchid.operations.portal.frontend: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]

我实际上没有web.xml,所以我需要它来组装没有它的战争。

我尝试在配置中添加一个虚假的&lt;webXml&gt;none&lt;/webXml&gt;,但这并没有改变任何东西...

我错过了什么?

【问题讨论】:

    标签: java maven maven-3 war maven-war-plugin


    【解决方案1】:

    这应该可行:

    <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
                <executions>
                    <execution>
                        <id>prepare-war</id>
                        <phase>prepare-package</phase>
                        <configuration>
                            <archiveClasses>false</archiveClasses>
                            <archive>
                                <manifest>
                                    <addClasspath>true</addClasspath>
                                    <classpathPrefix />
                                </manifest>
                                <manifestEntries>
                                    <Implementation-Build>${build.number}</Implementation-Build>
                                    <Implementation-Title>${project.name}</Implementation-Title>
                                    <Built-By>${user.name}</Built-By>
                                    <Built-OS>${os.name}</Built-OS>
                                    <Build-Date>${build.date}</Build-Date>
                                </manifestEntries>
                            </archive>
                            <webResources>
                                <resource>
                                    <!-- this is relative to the pom.xml directory -->
                                    <directory>./target/dist</directory>
                                </resource>
                            </webResources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
    

    请注意&lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt; 部分已移至插件配置而不是执行。

    【讨论】:

      【解决方案2】:

      POM 中的执行 ID 是 prepare-war。 Maven 为打包类型为war 的项目运行自己的默认war 插件执行。默认执行的 ID 为 default-war。由于当前配置了 POM,war 目标运行了两次。

      如果您查看错误消息:

      [ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.4:war (default-war) on project com.specktro.orchid.operations.portal.frontend: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]
      

      您可能会在括号 (default-war) 中看到失败的执行 ID。如果您将执行 ID 更改为 default-war,您的问题就会消失,并且您将不再有两个执行战争目标在运行。

      【讨论】:

        【解决方案3】:

        问题与您当前使用的版本有关。您需要查看本地存储库并查看已下载的版本。转到您的 .m2 文件夹并查找

        .m2\repository\org\apache\maven\plugins\maven-compiler-plugin
        

        在该文件夹中,您可以看到可供您使用的版本。

        将版本更改为文件夹中的版本即可!

        【讨论】:

          猜你喜欢
          • 2011-03-09
          • 2021-10-05
          • 1970-01-01
          • 1970-01-01
          • 2014-08-10
          • 2023-04-08
          • 2018-12-03
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多