views:

920

answers:

3

We have a solution with numerous wars. Wars are similar in the sense they all use hibernate and spring. This means that we have a number of same jars inside each war. This is becoming a problem, because the size of the ear is starting to grow out of proportion.

I would like to use Maven to calculate dependencies and to place all jars common to multiple wars to the root of the EAR.

I tried organizing my project using j2ee archetype (maven-archetype-j2ee-simple), but all wars are still packaged with dependencies inside the WEB-INF/lib. Is there a way to make Maven calculate common dependencies and place them to EAR, just as he is able to calculate all transitional dependencies when constructing a war or a jar?

+1  A: 

You can set the dependancies scope to "provided". This means they will be provided by some other module and will not be included in the final jar or war.

Perhaps the assembly plugin can help you when packaging up the final EAR and place common jars there.

Mike Pone
+2  A: 

http://maven.apache.org/plugins/maven-war-plugin/examples/skinny-wars.html

from suggested URL: "Now the painful part. Your EAR project's pom.xml needs to list every dependency that the WAR has. This is because Maven assumes fat WARs and does not include transitive dependencies of WARs within the EAR." I asked: I would like to use Maven to calculate dependencies... without using Maven to calculate dependencies, it is a no-go...
Dan
+1  A: 

Create a new artifact named commons-jars and package it as pom. It should depend on all the common jars you are using - Spring, Hibernate, Log4j, etc.

Then, in each on your wars add it as dependency with scope "provided" (and don't forget to set the type as pom). You will be able to see it in your classpath but they won't be packaged into the war. This way you can also have war specific dependencies packaged into it, which the solution from skinny wars does not provide.

David Rabinowitz