0

I was wondering if there was a way to select different versions of the same jar at runtime. I am hoping to avoid using maven profiles since this would be a build-time selection.

Lets say there are two versions of the same jar:

greatFeature_version_A.jar greatFeature_version_B.jar

My initial idea was to use JMX to create a basic runtime toggle selecting between those two jars which are both included in the classpath. Also, the contents of the two jars are the same (no versioning or different naming of the internal classes).

So when a class is requested, lets say from version_A, the class loader will always select the first one it finds, regardless of which jar it belongs to.

My thinking is that no effective runtime toggling can be achieved this way. I was wondering if anyone might have a experienced something similar and have a recommended workaround. I am also hoping to avoid writing a custom class loader if possible.

Many thanks!

P.S. Other related questions on SO indicate custom class loaders, like this one.

Community
  • 1
  • 1
denchr
  • 4,142
  • 13
  • 48
  • 51

1 Answers1

0

You can use jarjar to "rename" the packages so greatFeature_version_A.jar's packages start ajar.* and the other start bjar.* This way you can use the code from both jars in the same application, potentially at the same time.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130