Maven 2 如何让Maven管理战争:爆炸但不是战争:战争
我有一个Maven pom,它使用Maven 2 如何让Maven管理战争:爆炸但不是战争:战争,maven-2,Maven 2,我有一个Maven pom,它使用war。但实际上,我不想构建war文件,我只想收集所有依赖的JAR并创建一个完整的部署目录 因此,我正在运行war:exploded目标以生成部署目录: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <executions>
war
。但实际上,我不想构建war文件,我只想收集所有依赖的JAR并创建一个完整的部署目录
因此,我正在运行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>
org.apache.maven.plugins
maven战争插件
包裹
目标/${env}/deploy
真的
爆炸了的
问题是,war文件仍在生成中。有没有一种简单的方法让war
执行war:exploded
目标而不是war:war目标
还是有其他简单的方法可以做到这一点?据我所知(我对maven还是新手),这是不可能的。您可以跳过的唯一默认生命周期是“测试”。为了进行部署,您必须打包。您可以在此处阅读有关默认生命周期执行顺序的所有信息:我能想到的唯一方法是设置使用pom打包(或创建),并将所需目标从war打包绑定到生命周期的相关阶段。如果您选择pom打包,您可以在概要文件中使用define the war:war execution来打包它,但是您需要使用build helper maven插件将war附加到pom 注意:如果您想使用任何其他特定于战争的处理方法,这种方法可能会给您带来问题
战争包装的生命周期绑定被列在(参见“默认生命周期绑定——打包EJB/EJB3/JAR/PAR/RAR/WAR”部分)中。 要将相关插件执行绑定到pom包,请执行以下操作:
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>process-resources</id>
<phase>process-resources</phase>
<goals>
<goal>resources</goal>
</goal>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compile-plugin</artifactId>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goal>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>process-test-resources</id>
<phase>process-test-resources</phase>
<goals>
<goal>testResources</goal>
</goal>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goal>
</execution>
</executions>
</plugin>
<!-- package not wanted, install and deploy already defined for pom packaging-->
<!--define war:war execution in a profile in case it is needed-->
maven资源插件
过程资源
过程资源
资源
maven编译插件
编译
编译
编译
maven资源插件
过程测试资源
过程测试资源
测试资源
maven surefire插件
测试
测试
测试
根据包装阶段的war包装war:war mojo被称为
您可以调用上一个“准备包”阶段-所有操作都将执行,然后调用mojo war:exploded
mvn prepare-package war:exploded
结果将与您的相同,但不会产生战争。解决方案非常简单。您需要覆盖war插件的默认执行以禁用它,并添加您自己的执行(例如):
org.apache.maven.plugins
maven战争插件
默认战争
没有一个
战争爆发了
包裹
爆炸了的
我想升级到@Michael Wyraz answer,只要包括安装跳过设置,以防有人在多模块项目的顶层执行mvn clean install
构建,子模块之一是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>
执行
mvn clean install-p war\u explode
并使用此设置(包含在名为war\u explode的maven配置文件中)将完成构建,不会出错。war文件仍然会被创建,那又怎样?为什么这是个问题?我想这是因为他们想加快构建速度——至少这就是我使用这个的原因。我在maven上有一个基本的spring应用程序,但我正在使用Google App Engine,它被配置为扫描分解的war构建目录,所以要想看到变化,我需要构建分解的war——经常。有没有办法在项目中的任何文件发生更改时自动调用它?如果您真的喜欢,可以将war:exploded调用放入绑定到prepare package阶段的pom中。但是,如果您需要maven继续运行其余阶段,您将遇到一个问题,因此切换到packaging>pom会更好。我发现我的操作失败,因为它试图在“classes”文件夹中执行FileInputStream.open。然而,作为两个独立的命令运行时有效mvn prepare-package
,然后mvn-war:explodesd
ah-maven你这个神秘的家伙如果你把一个项目分成几个jar,这是行不通的-它们需要install
ed才能进入maven的静态缓存,以便在prepare-package中提取这是这里发布的最简单的解决方案。是的,这似乎是最好的答案。对我来说,这是一种魅力。:)你能给我解释一下这是怎么回事吗?您从哪里了解到禁用默认阶段目标绑定是使用id“default war”完成的?这是一个很好的解决方案-我花了一两次时间才完全理解并开始工作。+1。是不是默认的warnone实际上消除了战争的产生?因为没有它,再加上另一次处决,战争还是被制造出来了?提前感谢如果安装失败,它是正确的,因为没有安装,但这是假装它完成了。在分解的概要文件无法正确安装的情况下,为分解的和战争的封装制作概要文件可能更好。
<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>
[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]