Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use two versions of the same library in the same project in Java? [duplicate]

Tags:

java

jar

Let's say I'm using xmlsec-1.5.8.jar for one part of my application (it has always used this).

Then let's say I'm adding a new feature to my application and the new feature requires the use of xmlsec-2.0.5.jar.

I don't want to replace xmlsec's usage for all the old code because I don't want to re-test all the code that has already been working (much of the code of which I don't know how it works because it was created before I arrived at this company).

Is there a way in Java to use xmlsec-1.5.8.jar classes in one part of my project and then to use xmlsec-2.0.5.jar in another part?

like image 274
Brian T Hannan Avatar asked Aug 07 '15 18:08

Brian T Hannan


1 Answers

You need to look into class loaders.

It's pretty tricky, but here's a good explanation for you.

Java, Classpath, Classloading => Multiple Versions of the same jar/project

You'll probably have to unload the old jar, load the new jar, run whatever the new function are, then unload that newer jar and reload the older jar.

like image 157
StephenG Avatar answered Oct 05 '22 21:10

StephenG