我有一个使用<packaging>war</packaging>的Maven pom。但实际上,我并不想构建war文件,我只想收集所有依赖的war并创建一个完整的部署目录。
因此,我运行war:exploded目标来生成部署目录:
<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目标?
或者有其他简单的方法可以做到这一点?
发布于 2009-10-07 09:22:42
根据builtin lifecycle bindings对于包阶段的war打包:war mojo被称为。
你可以调用之前的'prepare-package‘阶段--所有的动作都将被执行,然后调用mojo war: after
mvn prepare-package war:exploded结果将与您的相同,但不会造成战争。
发布于 2012-06-21 17:08:51
解决方案非常简单。您需要覆盖war插件的默认执行以禁用它,并添加您自己的执行(对于松散的):
<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>发布于 2015-03-26 17:47:50
我想升级到@Michael Wyraz answer,并仅包括安装跳过设置,以防有人在多模块项目的顶层执行mvn clean install build,其中一个子模块是web应用程序。
这站在war模块内部:
<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文件夹中。错误消息如下:
[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时,将完成构建而不会出现错误。
https://stackoverflow.com/questions/352612
复制相似问题