Java classloader usage in OSGi

后端 未结 2 542
予麋鹿
予麋鹿 2021-01-21 18:33

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

2条回答
  •  清歌不尽
    2021-01-21 19:14

    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.

提交回复
热议问题