Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I do something after Maven copies the webapp resources during the `package` goal?

How do I do something after Maven copies the webapp resources to the war directory inside of the package goal? I want to do something just after it copies the webapp resources to the target's war directory, but just before it finally archives everything into a WAR file.

like image 661
egervari Avatar asked Dec 03 '11 22:12

egervari


2 Answers

The reason you're having problems is because the copying of webapp resources is done by the war plugin in the same breath that it builds the war. It's not a different lifecycle phase or even two different actions in the same phase. It's all part of the war:war goal.

There's a workaround, though. If you bind war:exploded to an earlier phase, like prepare-package, then it will build your exploded webapp, and then you can put something after that to modify the files that were built to the exploded directory. Then war:war will package up the modified exploded directory. (With newer versions of the war plugin, I believe you'll need to set the useCache property to get the desired behavior, though that doesn't seem to really be what it's for, be wary.)

like image 158
Ryan Stewart Avatar answered Oct 21 '22 13:10

Ryan Stewart


I've just had to do the same thing so here's an example for egervari to show what Ryan Stewart is saying.

(This uses the YUI Compressor Maven Mojo to automatically minify js files.)

        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.1.1</version>
                    <configuration>
                        <warName>${warName}</warName>
                        <useCache>true</useCache>
                    </configuration>
                    <executions>
                        <execution>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>exploded</goal>
                            </goals>
                      </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>net.alchim31.maven</groupId>
                    <artifactId>yuicompressor-maven-plugin</artifactId>
                    <version>1.1</version>
                    <executions>
                        <execution>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>compress</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <excludes>
                            <exclude>**/*.min.js</exclude>
                            <exclude>**/*.properties</exclude>
                        </excludes>
                        <nosuffix>true</nosuffix>
                    </configuration>
                </plugin>           
            </plugins>
        </build>
like image 7
Luke Avatar answered Oct 21 '22 15:10

Luke