Search code examples
mavenmaven-3maven-ear-plugin

maven - not copying project jar outside /lib while EAR packaging


This is happening while packaging the EAR

My pom.xml is packaging the ear file where it should include projectA.jar file and projectB.war outside the /lib folder. Apparently, projectA.jar file is going inside the /lib folder which is not supposed to be. I have my application.xml which tells that these two projects should be outside the lib.

Question : how do i instruct maven not to bundle projectA.jar inside the /lib folder but to bundle it outside the /lib folder?.

My EAR structure should be:

MyWebEAR

\lib
\META-INF
projectA.jar
ProjectB.war

Below is my pom.

<dependencies>
    <dependency>
        <groupId>com.xxx.sms</groupId> 
        <artifactId>projectA</artifactId> 
        <version>1.0-SNAPSHOT</version>             
    </dependency>
    <dependency>
        <groupId>com.xxx</groupId>
        <artifactId>projectB</artifactId>
        <version>1.0-SNAPSHOT</version>
        <type>war</type>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-ear-plugin</artifactId>
            <configuration>
                <defaultLibBundleDir>lib</defaultLibBundleDir>
                <earSourceDirectory>${basedir}</earSourceDirectory>
                <earSourceIncludes>META-INF/*</earSourceIncludes>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                    </manifest>
                </archive>
                <generateApplicationXml>false</generateApplicationXml>
                <applicationXML>${basedir}/META-INF/application.xml</applicationXML>
            </configuration>
        </plugin>
    </plugins>
    <finalName>MyWebEAR</finalName>
</build>

Thanks for your time.


Solution

  • You need to specifically define a jarModule configuration in the modules section of your maven-ear-plugin configuration for the projectA dependency and explicitly set where you want the jar placed.

    So your POM would be:

    <plugin>
        <artifactId>maven-ear-plugin</artifactId>
        <configuration>
            <defaultLibBundleDir>lib</defaultLibBundleDir>
            <earSourceDirectory>${basedir}</earSourceDirectory>
            <earSourceIncludes>META-INF/*</earSourceIncludes>
            <archive>
                <manifest>
                    <addClasspath>true</addClasspath>
                </manifest>
            </archive>
            <generateApplicationXml>false</generateApplicationXml>
            <applicationXML>${basedir}/META-INF/application.xml</applicationXML>
            <modules>
                <jarModule>
                    <groupId>com.xxx.sms</groupId>
                    <artifactId>projectA</artifactId>
                    <bundleDir>/</bundleDir>
                </jarModule>
            </modules>
        </configuration>
    </plugin>
    

    The value (/) in the bundleDir tells the maven-ear-plugin to place projectA's jar in the root folder of the ear instead of the default location of lib.

    You can see details on this in the plugins documentation here: http://maven.apache.org/plugins/maven-ear-plugin/examples/customizing-module-location.html