Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Supporting 2 versions of an API in Java

I'm trying to find a way to support 2 different versions of an API in my code base. They have the same package names but work much differently under the hood (two completely different systems). How can I do this?

Both of these API's also have a dependency on Bouncy Castle but they use different versions of it. How do I also take this into account?

like image 473
Rob Avatar asked May 17 '16 12:05

Rob


1 Answers

I would not recommend this unless you know what you're doing but you could use a URLClassLoader as follows:

URLClassLoader classLoaderA = URLClassLoader.newInstance(new URL[] {new URL("versionA.jar")});
URLClassLoader classLoaderB = URLClassLoader.newInstance(new URL[] {new URL("versionB.jar")});

Load the class:

classLoaderA.loadClass("SomeClass");

Another option is to have a look at OSGI.

like image 118
Diyarbakir Avatar answered Sep 22 '22 03:09

Diyarbakir