Maven packaging based on maven-war-plugin

1.7k views Asked by At

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?

3

There are 3 answers

0
jtahlborn On BEST ANSWER

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.

0
Hans Beemsterboer On

Can you try invoking the maven-assembly-plugin during the 'install' phase?

0
AudioBubble On

You can change the phase of each task.

1) Create the War file during the prepare-package phase

<phase>prepare-package</phase>

2) Create the zip file during the package phase

<phase>package</phase>