首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何让Maven运行war:爆炸而不是war:war

如何让Maven运行war:爆炸而不是war:war
EN

Stack Overflow用户
提问于 2008-12-09 12:49:59
回答 5查看 37K关注 0票数 60

我有一个使用<packaging>war</packaging>的Maven pom。但实际上,我并不想构建war文件,我只想收集所有依赖的war并创建一个完整的部署目录。

因此,我运行war:exploded目标来生成部署目录:

代码语言:javascript
复制
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <executions>
        <execution>
            <phase>package</phase>
            <configuration>
                <webappDirectory>target/${env}/deploy</webappDirectory>
                <archiveClasses>true</archiveClasses>
            </configuration>
            <goals>
                <goal>exploded</goal>
            </goals>
        </execution>
    </executions>
</plugin>

问题是,war文件仍然会被构建。有没有一种简单的方法可以让<packaging>war</packaging>执行war:exploded目标而不是war:war目标?

或者有其他简单的方法可以做到这一点?

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2009-10-07 09:22:42

根据builtin lifecycle bindings对于包阶段的war打包:war mojo被称为。

你可以调用之前的'prepare-package‘阶段--所有的动作都将被执行,然后调用mojo war: after

代码语言:javascript
复制
mvn prepare-package war:exploded

结果将与您的相同,但不会造成战争。

票数 48
EN

Stack Overflow用户

发布于 2012-06-21 17:08:51

解决方案非常简单。您需要覆盖war插件的默认执行以禁用它,并添加您自己的执行(对于松散的):

代码语言:javascript
复制
<pluginManagement>
    <plugins>
            <plugin><!-- don't pack the war  -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default-war</id>
                        <phase>none</phase>
                    </execution>
                    <execution>
                        <id>war-exploded</id>
                        <phase>package</phase>
                        <goals>
                            <goal>exploded</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
    </plugins>
</pluginManagement>
票数 81
EN

Stack Overflow用户

发布于 2015-03-26 17:47:50

我想升级到@Michael Wyraz answer,并仅包括安装跳过设置,以防有人在多模块项目的顶层执行mvn clean install build,其中一个子模块是web应用程序。

这站在war模块内部:

代码语言:javascript
复制
<profiles>
    <profile>
        <id>war_explode</id>
        <build>
            <pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-war-plugin</artifactId>
                        <version>2.6</version>
                        <executions>
                            <execution>
                                <id>default-war</id>
                                <phase>none</phase>
                            </execution>
                            <execution>
                                <id>war-exploded</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>exploded</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-install-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>default-install</id>
                                <phase>none</phase>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </pluginManagement>
        </build>
    </profile>
</profiles>

如果不安装,跳过构建会失败,因为它会尝试将war安装到.m2文件夹中。错误消息如下:

代码语言:javascript
复制
[INFO] --- maven-install-plugin:2.4:install (default-install) @ *** ---
[INFO]   ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.4:install (default-install) on project ***: The packaging for this project did not assign a file to the build artifact -> [Help 1]

使用此设置(包含在名为war_explode的maven配置文件中)执行mvn clean install -P war_explode时,将完成构建而不会出现错误。

票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/352612

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档