Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如果我将maven-war插件配置为在缺少web.xml时不失败,那么为什么web.xml的maven-war插件会失败呢?_Java_Maven_Maven 3_War_Maven War Plugin - Fatal编程技术网

Java 如果我将maven-war插件配置为在缺少web.xml时不失败,那么为什么web.xml的maven-war插件会失败呢?

Java 如果我将maven-war插件配置为在缺少web.xml时不失败,那么为什么web.xml的maven-war插件会失败呢?,java,maven,maven-3,war,maven-war-plugin,Java,Maven,Maven 3,War,Maven War Plugin,这里有一个挑战:为什么这个构建失败了 我已将Maven的Maven war插件配置为在一个缺席的web.xml文件上不会失败,看起来: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <executions>

这里有一个挑战:为什么这个构建失败了

我已将Maven的Maven war插件配置为在一个缺席的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>
实际上我没有web.xml,所以我需要它来组装没有它的战争

我试图在配置中添加一个假的
none
,但这并没有改变任何事情

我遗漏了什么?

这应该可以:

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

org.apache.maven.plugins
maven战争插件
假的
备战
准备包装
假的
真的
${build.number}
${project.name}
${user.name}
${os.name}
${build.date}
/目标/距离

请注意,
false
部分已上移到插件配置,而不是执行。

POM中的执行ID是
prepare war
。Maven为打包类型为
war
的项目运行自己的默认war插件执行。默认执行具有ID
默认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
(默认war)
。如果将执行ID更改为默认war,则问题将消失,war目标将不再执行两次。

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

.m2\repository\org\apache\maven\plugins\maven-compiler-plugin
在该文件夹中,您可以看到可供您使用的版本

更改文件夹中版本的版本,它就会工作

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