Mira
Mira

Reputation: 291

Maven : Remove duplicate jars from EAR

We are using maven to build an EAR that contains WAR, the JARS are duplicated on both EAR's root and WAR's lib folder, I read about the skinny jars to remove the jars from the WAR but I don't want this as I want to keep the WAR as stand alone unit,
IS there a way to do it the other way around and remove the JARs from the EAR's root folder ?
attached is the EAR POM

    <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ear-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <modules>
                    <webModule>
                        <groupId>com.csv.xyz</groupId>
                        <artifactId>web</artifactId>
                    </webModule>
                </modules>
            </configuration>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>com.csv.xyz</groupId>
        <artifactId>web</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <type>war</type>
        <scope>compile</scope>
    </dependency>
</dependencies>

Upvotes: 1

Views: 4212

Answers (4)

mario
mario

Reputation: 65

What you are asking is the default behavior if you are not using skinny wars. When building a multi-module project, the dependencies and transitive dependencies of the WAR is not added to the EAR dependencies list. This is because by default the WAR dependencies are added to the WEB-INF/lib folder in the WAR.

Upvotes: 0

Turbokiwi
Turbokiwi

Reputation: 1298

The "maven-skinny-war" solution isn't any drawback in your case. Also have a look at this question and my answer: How to make maven place all jars common to wars inside the same EAR to EAR root?

With this solution you will first get WARs packaged with their own dependencies and second, an EAR module with skinny WARs. So everything is deployable on its own and nothing is duplicated.

Upvotes: 2

Allen Parslow
Allen Parslow

Reputation: 209

To remove a dependency from the EAR lib folder, declare the dependencies as provided in the EAR pom, for example to remove commons-lang:

<dependencies>  
    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.6</version>
        <scope>provided</scope>
    </dependency>    
</dependencies>

Just make sure if you have EJB modules that they don't require the dependency! Also webModules do not contribute to the EAR's root lib folder, do you have more dependencies in you ear pom?

Upvotes: 0

Christian Schlichtherle
Christian Schlichtherle

Reputation: 3155

I don't think this would be a good idea because of the class loader architecture. If a JAR is part of a WAR, it's defined by the web app class loader, which may result in multiple instances. If it's part of an EAR, it's defined by the enterprise app class loader, which is a different class loader.

Upvotes: 1

Related Questions