javamaventomcatmaven-war-plugin

War external dependency overlay - move jars from WEB-INF/lib-new to WEB-INF/lib


I am working on a maven project with a war external dependency (let's call this war dependency WAR-DEP)

After the build and during the package phase I am taking the content of WAR-DEP and merging it with the content of the current build using the overlay feature of the maven-war plugin.

In WAR-DEP we have some required jars in it's WEB-INF/lib folder so with the overlay we end up getting everything we need in our final war but our problem started when the project providing us with the WAR-DEP war added a new folder in the WEB-INF/lib-new and moved some of the jars we had before in the WEB-INF/lib folder to this new folder WEB-INF/lib-new.

After building with this new version of the WAR-DEP the overlay worked as expected so we ended up having two folders in the WEB-INF (lib and lib-new) and our application stopped working since this WEB-INF/lib-new is not recognized by tomcat server. So without changing the classpath on tomcat side is there a way I can move the content of lib-new into the lib folder before generating the war ? I mean for example during the overlay but I am not sure how to do this. Thanks for your inputs.


Solution

  • maven-war-plugin does not have required functionality, however maven-dependency-plugin may help, smth. like:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>3.3.0</version>
        <executions>
            <execution>
                <id>unpack-lib-new</id>
                <goals>
                    <goal>unpack</goal>
                </goals>
                <phase>prepare-package</phase>
                <configuration>
                    <artifactItems>
                        <artifactItem>
                            <groupId>dep-group-id</groupId>
                            <artifactId>dep-artifiact-id</artifactId>
                            <version>dep-version</version>
                            <type>war</type>
                            <outputDirectory>${project.build.directory}/${build.finalName}/WEB-INF/lib</outputDirectory>
                            <includes>WEB-INF/lib-new/*</includes>
                            <fileMappers>
                                <org.codehaus.plexus.components.io.filemappers.FlattenFileMapper/>
                            </fileMappers>
                        </artifactItem>
                    </artifactItems>
                </configuration>
            </execution>
        </executions>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.3.2</version>
        <configuration>
            ...
            <overlays>
                <!-- current project -->
                <overlay/>
                <overlay>
                    <id>dep-skip-lib-new</id>
                    <groupId>dep-group-id</groupId>
                    <artifactId>dep-artifact-id</artifactId>
                    <excludes>
                        <exclude>WEB-INF/lib-new/*</exclude>
                    </excludes>
                </overlay>
            </overlays>
            ...
        </configuration>
    </plugin>