Java Reference
In-Depth Information
the dreaded ClassNotFoundException s at runtime.) We say a bundle is wired to
another bundle if it provides classes to that bundle.
Dependencies may be declared with Import-Package: or Require-Bundle: head-
ers. As we explained in chapter 5, using Import-Package: is a best practice.
A.3.4
Classloading
OSG i's classloading uses a different model from conventional Java classloading.
Instead of every class in the virtual machine being loaded by a single monolithic class-
loader, classloading responsibilities are divided among a number of classloaders (see
figure A.2). Each bundle has an associated classloader that loads classes contained
within the bundle itself. If a bundle is wired to a second bundle, its classloader will del-
egate to the other bundle's classloader for classes exported by the second bundle. In
addition to the bundle classloaders, there are environment classloaders that handle
core JVM classes.
Each classloader has well-defined responsibilities. If a classload request can't be sat-
isfied, it will pass it up the delegation chain (see figure A.3).
JVM
Bundle C
Classloader C
delegation
wiring
delegation
Environment
classloader
Bundle B
Classloader B
delegation
wiring
delegation
Bundle A
Classloader A
Figure A.2 The JVM contains many active classloaders in an OSGi environment. Each bundle has
its own classloader. These classloaders delegate to the classloaders of other bundles for imported
classes, and to the environment's classloader for core classes.
Search WWH ::




Custom Search