Java Reference
In-Depth Information
You use the Require-Bundle header to specify a bundle dependency in a manifest,
like this:
Require-Bundle: A; bundle-version="[1.0.0,2.0.0)"
Resolving required bundles is similar to
imported packages. The framework tries
to satisfy each required bundle; if it's
unable to do so, the bundle can't be
used. The framework resolves the depen-
dency by searching the installed bundles
for ones matching the specified symbolic
name and version range. Figure 5.9 shows
a resolved bundle dependency.
To a large degree, requiring bundles
is just a brittle way to import packages,
because it specifies who instead of what . The significant difference is how it fits into the
overall class search order for the bundle, which is as follows:
1 Requests for classes in java. packages are delegated to the parent class loader;
searching stops with either a success or failure (section 2.5.4).
2 Requests for classes in an imported package are delegated to the exporting
bundle; searching stops with either a success or failure (section 2.5.4).
3 Requests for classes in a package from a required bundle are delegated to the
exporting bundle; searching stops if found but continues with the next
required bundle or the next step with a failure.
4 The bundle class path is searched for the class; searching stops if found but con-
tinues to the next step with a failure (section 2.5.4).
5 If the package in question isn't exported or required, requests matching any
dynamically import package are delegated to an exporting bundle if one is
found; searching stops with either a success or failure (section 5.2.2).
Packages from required bundles are searched only if the class wasn't found in an
imported package, which means imported packages override packages from required
bundles. Did you notice another important difference between imported packages
and packages from required bundles in the search order? If a class in a package from
a required bundle can't be found, the search continues to the next required bundle
in declared order or the bundle's local class path. This is how Require-Bundle sup-
ports split packages, which we'll discuss in more detail in the next subsection. First,
let's look at the remaining details of requiring bundles.
As we briefly mentioned in section 5.2.4, it's also possible to optionally require a
bundle using the resolution directive:
export
javax.servlet.http
version="2.4.0"
require A
bundle-version="[1.0.0, 2.0.0)"
B
A
1.0 . 0
export
javax.servlet
version="2.4.0"
Figure 5.9 Requiring a bundle is similar to
explicitly importing every package exported
by the target bundle.
Require-Bundle: A; bundle-version="[1.0.0,2.0.0)"; resolution:="optional"
The meaning is the same as when you optionally import packages, such as not impact-
ing dependency resolution and the need to catch ClassNotFoundException s when
Search WWH ::




Custom Search