0

If there is a class com.app.A from JAR-1 loaded into the JVM then how can we load a new version of the same class com.app.A from another JAR-2 at runtime?

What are the different ways to do this?

- Abhijit

AbhijitG
  • 59
  • 1
  • 1
  • 8

2 Answers2

0

One way is OSGi. You can have multiple versions of the same bundle (jar) in an OSGi environment.

Say we have JAR-1 and JAR-2 in OSGi runtime exposing the same packages but different versions like this.

JAR-1 exports > org.home.code;version=1.0.0
JAR-2 exports > org.home.code;version=2.0.0

Now when some other jar needs org.home.code as a dependency, it can specify which version it needs.

You can find some popular OSGi implementations here.

Bee
  • 12,251
  • 11
  • 46
  • 73
0

You have two options:

First: You can do it like it described here:

Java ClassLoader: load same class twice

Second: You can just manually try to replace old *.class to new one. You can catch plenty of exceptions if you made significant changes, like added methods etc. I changed some logging, made some internal method refactoring and it worked for me.

Community
  • 1
  • 1
Rudziankoŭ
  • 10,681
  • 20
  • 92
  • 192