How to make Maven wage war: exploded, but not war: war

I have a Maven pom that uses <packaging>war</packaging> . But in fact, I do not want to build a war file, I just want all dependent banks to be assembled and a full deployment directory created.

So, I run the war:exploded to create the deployment directory:

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

The trouble is that the war file is still under construction. Is there an easy way to have <packaging>war</packaging> fulfill the goal of war:exploded instead of the goal of war: war?

Or is there another easy way to do this?

+45
maven-2
Dec 09 '08 at 12:49
source share
5 answers

According to the built-in life cycle bindings for military packaging in the phase of packaging phases: the mojo war is fired.

You can call the previous โ€œprepare-packageโ€ phase - all actions will be performed after this call mojo war: exploded

 mvn prepare-package war:exploded 

The results will be the same as yours, but no war has been created.

+40
Oct 07 '09 at 9:22
source share

The solution is quite simple. You need to override the default plug-in execution of the war in order to disable it and add your own execution (for exploding):

 <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> 
+62
Jun 21 2018-12-12T00:
source share

The only way I can do what you want is to install the pom package (or create a custom package ) and associate the required goals with the packaging war at the appropriate stages of the life cycle. If you go to pom packing, you can use the definition of war: military execution in the profile so you can pack it, but you need to use build-helper-maven-plugin attach-artefact goal to attach the war to pom.

Pay attention to this approach if you want to use any other war-related processing that can cause problems.

life-cycle bindings for military packaging are listed in Introduction to the Assembly Life Cycle (see "Default Life-Cycle Binding - ejb / ejb3 / jar / par / rar / war packaging").

To associate the appropriate plugins with the pom package, you must do the following:

 <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--> 
+5
Sep 19 '09 at 22:55
source share

I would like to update the answer to @Michael Wyraz and just enable skip settings if someone runs mvn clean install build at the top level of a project with several modules, and one of the submodules is a web application.

This is inside the war module:

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

Without installation, skip the crash assembly when trying to install war in the .m2 folder. The error message is as follows:

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

Performing mvn clean install -P war_explode with these settings (nested in the maven profile named war_explode), it completes the build without errors.

+4
Mar 26 '15 at 9:47
source share

As far as I know (I'm still new to maven) this is not possible. The only default life cycle that you can skip is the "test". To get to the deployment, you need to pack. Here you can read all about the default life cycle order: http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference

0
Dec 17 '08 at 19:55
source share



All Articles