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

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?

Best Answer

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