10

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

我已将 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,所以我需要它来组装没有它的战争。

我尝试在配置中添加一个伪造<webXml>none</webXml>的,但这并没有改变任何东西......

我错过了什么?

4

3 回答 3

11

这应该有效:

<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>

请注意,该<failOnMissingWebXml>false</failOnMissingWebXml>部分已移至插件配置而不是执行。

于 2014-06-18T17:39:21.767 回答
6

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]

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

于 2014-06-18T19:09:56.443 回答
0

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

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

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

将版本更改为您文件夹中的版本,它可以工作!

于 2019-01-16T16:29:46.517 回答