What is the difference between bootdelegation and

2019-05-04 00:08发布

问题:

Both will resolve package dependencies in osgi what is the difference between them

回答1:

Bootdelegation is a hack that is needed because some code inside the VM assumed that application class loaders had visibility to com.sun.* classes. In OSGi, this is obviously NOT the case. Boot delegation is parameter that specifies for which packages the framework may do a lookup on the boot classpath. Since this is not modular, don't do it. It is global for the framework.

DynamicImport-Package is similar but only for the bundle it is defined in and only for exported packages. If a package cannot be found in the normal bundle contents or Import-Package then a DynamicImport-Package specifies the patterns of packages that are allowed to be searched in the set of exported packages. This idea is similar to the classpath, you've no idea what version you're going to get. Once a package is found, it is used forever. However, if it is not found every access will keep looking. I.e. you can install the package after the fact without restarting the bundle.



回答2:

Packages imported via DynamicImport-Package are resolved every time a class from the package is needed. So if the package is not available due the resolving process, it will not fail. By this way, ClassNotFoundExceptions may be thrown at runtime. (compare this to optional imports)

BootDelegation classes will be loaded from the bootdelegation class loader, which is the class loader which loads the OSGi framework into the JVM http://wiki.osgi.org/wiki/Boot_Delegation http://www2.sys-con.com/itsg/virtualcd/java/archives/0808/chaudhri/index.html http://de.slideshare.net/honnix/osgi-class-loading



标签: java osgi