Search code examples
javamavenmaven-war-plugin

Maven packaging based on maven-war-plugin


I am wondering about the steps required with Maven to implement custom packaging and bind it to the 'package' phase.

Basically what I need is to invoke standard maven-war-plugin and create ZIP archive of a specific structure that will contain created WAR file. While I know how to do these tasks separately, I do not quite understand how to tie them together.

I assume a sequence like this:

  1. At some phase maven-war-plugin is invoked. It automatically handles WAR-specific stuff and creates the WAR file

  2. During 'package' phase maven-assembly-plugin is invoked. It creates ZIP archive of the required structure.

What would be the most straightforward and proper way to define these tasks in POM file and bind them to the build life cycle?


Solution

  • We generally just run the assembly during the package phase, using the standard assembly config:

                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>attached</goal>
                        </goals>
                    </execution>
                </executions>
    

    if that is not working for you for some reason, an easy solution is to split the war and the zip into 2 submodules. generate the war in the first sub-module, then create a second sub-module of type "pom" which runs the assembly plugin.