mercredi 31 mai 2017

How to load 2 versions of the same Jar in 1 class Java

This is a complicated question but I will do my best to describe my problem.

I need to load 2 versions of the same JAR in a top level class (v1.jar and v2.jar) so I have access to both versions of the jar. The reason for this is because I want to test if any feature in v2.jar has regressed from v1.jar

In my top level class, I want to call methods of v1.jar and v2.jar and then validate the output from v1 against v2 output. This way I can be certain nothing got screwed up.

I can't import v1 and v2 jars as maven dependencies since this will create a version conflict in maven and by default maven will use the newest jar. So I thought about creating a common interface and having 2 different implementation classes of that interface. Then in the toplevel I can use class loaders to load v1 and v2 jars, etc. But this way not work since I would have to change production v1.jar to implement the common interface.

Any help or insight will be much appreciated. I'd very much like to see samples if possible. And please don't refer me to other threads





Aucun commentaire:

Enregistrer un commentaire