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

0

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.