samedi 5 février 2022

Interact with multiple versions of an external jar file

JavaApplication1 wants to instantiate objects defined in the jar file of (fully trusted) JavaApplication2. Not normally a problem - add the external JavaApplication2 jar file to the build path of the JavaApplication1 project and then import the appropriate classes. Simples.

But imagine a scenario where JavaApplication1 needs to use multiple different historical versions of JavaApplication2 at the same time. e.g. Instantiate an instance of a JavaApplication2Object from version 1.5 of JavaApplication2.jar, and then, in the same thread, instantiate a separate instance of JavaApplication2Object from version 1.8 of JavaApplication2.jar.

In C#, I would use reflection to load and interact with the correct DLL. How does one do the same thing in Java in order to deal with the fact that the namespaces and class names are all identical across all versions of JavaApplication2?





Aucun commentaire:

Enregistrer un commentaire