How to avoid Jar conflicts (Jar Hell) with container libraries

What is Jar hell?

Jar hell or classpath hell or dependency hell is a term used to describe all the various ways in which the classloading process can end up not working. It ends with this list of the different circles of JAR hell: unexpressed dependencies, transitive dependencies shadowing, version conflicts, complex class loading.

Simple solution

Overwrite jar file in container by your libraries. Simply, copy your libraries to folder container/lib or some kind like that.

Several pitfalls may occur:
• We have to do it every freaking time we deploy the project.
• Depending on the container, we have to know how to do it properly.
• If we get the bad luck that the version we prefer to use is not compatible with the container, we may get more problem at runtime.

Use maven-shade-plugin

A better way is shading them. maven-shade-plugin  provides the capability to package the artifact in an uber-jar, including its dependencies and to shade – i.e. rename – the packages of some of the dependencies.


How to do

For example, we have Google Guice  lib is conflicting with Container

Step 1

Create a new maven project, for example guice-repacked

Step 2