IF we have a project using 2 external libraries. These 2 libraries will use the same jar file say abc.jar but with different versions 2.0 and 3.0. And, the main project also tries to import some class from these jar files which have different code base in the two versions may be some methods are updated or some logic is implemented differently. So, how the import and jar file version will be resolved in such cases? And, will it be possible to have both versions of jar files on the classpath?
You would want to avoid that situation if you could. Perhaps by modifying the code which uses the old version, or something. But sure, it might happen that you can't deal with that problem because the code which uses the old version isn't under you control and doesn't have a path to upgrade it.
But no, you can't have both versions of abc.jar in the classpath.
Presumably the code which requires the old version can be segregated from the code which requires the new version -- if that isn't the case then it needs to be fixed. And you aren't going to have acquired that code from somebody else, because it won't run for them either, it's going to be your code.
So what's left is that you have some code, and some part of it requires the old version and some other part of it requires the new version.
The way to deal with that is to have one of the two parts use a separate classloader which loads classes from one of the two jars.
I'm not going to go into detail about how to do that because it may well be that you' re just asking a theoretical question and you don't actually have a request on your desk to make that project work. I will just say at this point that URLClassLoader is your friend.
Here. Have a potato. I grew it in my armpit. And from my other armpit, this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop