discuss: classloader hierarchy to solve JAR dependency hell?
Scenario:
You want to use two ibraries A and B that depend on a certain library C. C has different versions, say V.1 and V.2.
Library A depends on the new version V.2 of C and calls newly-added methods, and B depends on the old version V.1 of C and calls deprecated methods that have been removed in V.2.
Now we're in dependency hell. We can't use both versions of C the same time.
Idea:
Create a classloader hierarchy, where A and B get their own classloaders.
Global Classloader (loads other libs)
|
|- Classloader for library A (loads V.2 of C)
|- Classloader for library B (loads V.1 of C)
Let the classloader for library A load V.2 of C and the classloader for B load V.1 of C. All other classes are loaded by the global classloader.
A class should be looked up in the "library classloaders" first, and when not found there, in the "global classloader". That way, each library could gets its required version of the library without causing library confilcts.
How do you like the suggested idea?
Do you think this is possible or know of an implementation or similar solution of the problem, especially for web containers?
Best regards,
Sebastian

