Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strategy to stop duplicate jars being deployed in ear-file

I have a problem with ear files to get the same libraries in several places and therefor creating conflicts. The problem is that we use a lot of 3:rd party libs that we simply doesn't control. So, we end up with throwing in a lot of excludes everywhere and that doesn't seem right to me, it is kind of error-prone and we don't detect the problem on our local installations of jboss either.

So, I'd like to perform some kind of pre-package-step that simply removes the duplicate jar-files. If deployed in two places, remove those that are in dependant projects. For instance jboss-seam.jar is included in several projects we use. Some of these dependencies are general and included in the parent.pom. Some of the dependences are ejb-specific or web-specific and is therefore included in the ejb and/or web-project. In the ear-file the jboss-seam.jar is included in three places and messes upp the classloader. So there should be some mechanism that simply checks some simple rule like, if in ear, should not be in war instead of having to create xml-hell with excludes.

Is there a better way to handle the problem?

like image 232
Roland Avatar asked Nov 04 '22 05:11

Roland


1 Answers

Sounds like you are using maven to build your artifacts? If so, the best recourse is the <exclusions> tag.

Using mvn dependency:tree with liberal application of grep it's quick to find which 3rd party artifacts that contribute conflicting versions of transitive dependencies.

I understand your sentiment about it not seeming right, and in a perfect world everyone should be better to write POMs for their published artifacts, but this is an imperfect world... I'm actually not even sure it could ever work perfectly for all situations, perhaps someone with better knowledge of maven can elaborate on that.

In the case of the same artifact being present in eg. both ear/lib/ and ear/webapp/WEB-INF/lib you could use <scope>provided</scope> in the the webapp's POM:

<dependency>
    <artifactId>spring-core</artifactId>
    ...
    <scope>provided</scope>
</dependency>

At least on Weblogic this works by default if you put the jar in the <earfile>/APP-INF/lib folder, and for other EE containers I believe you can achieve the same adding

<application>
    <library-directory>APP-INF/lib</library-directory>
</application>

to the application.xml descriptor.

I hope that helps.

Cheers,

like image 99
Anders R. Bystrup Avatar answered Nov 15 '22 00:11

Anders R. Bystrup