mavenwarearmaven-ear-pluginskinny-war

How do I make the "skinnyWar" option work when building an EAR file using Maven?


I'm using Maven 3.3.9. I'm creating an EAR project and have specified this in my POM ...

    <packaging>ear</packaging>

I would like to use the "skinnyWars" option, whereby the WAR files packaged in my EAR reference a set of libraries from within the EAR as opposed to their each having their own copy of a JAR. So for example, in my dependencies section I have stuff like

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>${version.mysql}</version>
    </dependency>

I have the below maven-ear-plugin configuration set up

<build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
        <plugin>
            <artifactId>maven-ear-plugin</artifactId>
            <version>2.10.1</version>
            <configuration>
                <finalName>${project.artifactId}</finalName>
                <version>5</version>
                <generatedDescriptorLocation>${basedir}/src/main/application/META-INF</generatedDescriptorLocation>
                <configuration>
                    <defaultLibBundleDir>lib/</defaultLibBundleDir>
                    <skinnyWars>true</skinnyWars>
                </configuration>
                <modules>
                    <webModule>
                        <groupId>org.mainco.subco</groupId>
                        <artifactId>moduleA</artifactId>
                        <uri>moduleA.war</uri>
                        <bundleFileName>moduleA.war</bundleFileName>
                        <contextRoot>/moduleA</contextRoot>
                    </webModule>
                    <webModule>
                        <groupId>org.mainco.subco</groupId>
                        <artifactId>moduleC</artifactId>
                        <uri>moduleC.war</uri>
                        <bundleFileName>moduleC.war</bundleFileName>
                        <contextRoot>/moduleC</contextRoot>
                    </webModule>
                    <webModule>
                        <groupId>org.mainco.subco</groupId>
                        <artifactId>moduleB</artifactId>
                        <uri>moduleB.war</uri>
                        <bundleFileName>moduleB.war</bundleFileName>
                        <contextRoot>/moduleB</contextRoot>
                    </webModule>
                    <webModule>
                        <groupId>org.mainco.subco</groupId>
                        <artifactId>moduleD</artifactId>
                        <uri>moduleD.war</uri>
                        <bundleFileName>moduleD.war</bundleFileName>
                        <contextRoot>/moduleD</contextRoot>
                    </webModule>
                </modules>
            </configuration>
        </plugin>

but when I run

mvn clean install

Although I see lines in the output like like

[INFO] Copying artifact [jar:mysql:mysql-connector-java:5.1.22] to [mysql-connector-java-5.1.22.jar]

The shared JAR file "mysql-connector-java-5.1.22.jar" is at the root of the EAR and not in a "lib" directory as specified in my configuration. In fact, the "lib" directory is not created at all. What's worse, the WAR files packaged within the EAR still contain their own copies of the libraries I want them to share. Why isn't my current "skinnyWar" configuration working and what tweaks do I need to make so that it will?


Solution

  • You should change your configuration like this:

         <plugin>
            <artifactId>maven-ear-plugin</artifactId>
            <version>2.10.1</version>
            <configuration>
                <finalName>${project.artifactId}</finalName>
                <version>5</version>
                <generatedDescriptorLocation>${basedir}/src/main/application/META-INF</generatedDescriptorLocation>
                <defaultLibBundleDir>lib/</defaultLibBundleDir>
                <skinnyWars>true</skinnyWars>
                <modules>
                    <webModule>
                        <groupId>org.mainco.subco</groupId>
                        <artifactId>moduleA</artifactId>
                        <uri>moduleA.war</uri>
                        <bundleFileName>moduleA.war</bundleFileName>
                        <contextRoot>/moduleA</contextRoot>
                    </webModule>
                    <webModule>
                        <groupId>org.mainco.subco</groupId>
                        <artifactId>moduleC</artifactId>
                        <uri>moduleC.war</uri>
                        <bundleFileName>moduleC.war</bundleFileName>
                        <contextRoot>/moduleC</contextRoot>
                    </webModule>
                    <webModule>
                        <groupId>org.mainco.subco</groupId>
                        <artifactId>moduleB</artifactId>
                        <uri>moduleB.war</uri>
                        <bundleFileName>moduleB.war</bundleFileName>
                        <contextRoot>/moduleB</contextRoot>
                    </webModule>
                    <webModule>
                        <groupId>org.mainco.subco</groupId>
                        <artifactId>moduleD</artifactId>
                        <uri>moduleD.war</uri>
                        <bundleFileName>moduleD.war</bundleFileName>
                        <contextRoot>/moduleD</contextRoot>
                    </webModule>
                </modules>
            </configuration>
        </plugin>