Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Maven to run war:exploded but not war:war

Tags:

maven-2

I have a Maven pom that uses <packaging>war</packaging>. But actually, I don't want build the war-file, I just want all the dependent jars collected and a full deployment directory created.

So I'm running the war:exploded goal to generate the deploy 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, the war file still gets built. Is there a simple way of having <packaging>war</packaging> execute the war:exploded goal instead of the war:war goal?

Or is there another simple way to do this?

like image 393
Adrian Pronk Avatar asked Dec 09 '08 12:12

Adrian Pronk


People also ask

What is an exploded WAR file?

WAR files are convenient because they are a single package that is easy to copy, and the contents of the WAR file are compressed making it quite a compact package. The second way is to deploy all the individual files that make up a web application. This is called an exploded deployment, or an exploded WAR.

What is war in Maven?

war:war is the default goal invoked during the package phase for projects with a packaging type of war . It builds a WAR file. war:exploded is generally used to speed up testing during the developement phase by creating an exploded webapp in a specified directory.

Can we add war as dependency?

war file as a classpath. Create a Maven module which contains the classes of project-orange with jar packaging. Now you can treat the new Maven module as normal dependency. Configure the maven-war-plugin such that it will build the .


2 Answers

The solution is quite simple. You need to override the default execution of the war plugin to disable it and add your own execution (for exploded):

<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> 
like image 107
Michael Wyraz Avatar answered Oct 26 '22 09:10

Michael Wyraz


According builtin lifecycle bindings for war packaging in package phase war:war mojo is called.

You can call previous 'prepare-package' phase - all actions will be performed and after that call mojo war:exploded

mvn prepare-package war:exploded 

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

like image 29
cetnar Avatar answered Oct 26 '22 11:10

cetnar