Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically manage two jar files with the same package and class names

I have two jar files from a client, one of which is used for a testing and another for final versions. Currently I put them in different folders and modify the library path when deploying our code, but it would be nice to be able to load both jar files and switch between them dynamically at runtime.

Is this possible?

like image 901
justinhj Avatar asked Dec 28 '22 23:12

justinhj


1 Answers

You can always write your own ClassLoader and chain it with the standard ClassLoader.

http://download.oracle.com/javase/6/docs/api/java/lang/ClassLoader.html

I used this method 10 years ago to load classes that were recieved via sockets and specified in an XML file (via sockets as well). My java program didn't know that the classes even existed before it got the XML file and the classes.

like image 135
bb121622 Avatar answered Dec 31 '22 15:12

bb121622