I have a question about the usage of Java ClassLoader in OSGi.
I wrote two OSGi bundles, namely server bundle and client bundle.
In server bundle, I implemented
You said: "In my knowledge, when class B is referenced in class A, the classloader of class B is the same as class A's classloader. But in OSGi, it seems not this way."
This is not a true statement about Java classloaders... whether or not you are using OSGi.
For example, every class you write extends from java.lang.Object
. Your class is loaded by the application classloader, but java.lang.Object
is loaded by the boot classloader. This works because of delegation: one classloader can ask another classloader to load a class on its behalf.
In OSGi it's exactly the same thing. Each bundle has a classloader, and when you import a package from another bundle, that other bundle's classloader is used to load them.