Java Reference
In-Depth Information
require A
bundle-version="[1.0.0, 2.0.0)"
visibility:=reexport
export
javax.servlet.http
version="2.4.0"
export
javax.servlet.http
version="2.4.0"
B
A
1.0
.0
Figure 5.10
When bundle B
requires bundle A with
reexport
visibility, any packages exported
from A become visible to any
bundles requiring B.
export
javax.servlet
version="2.4.0"
export
javax.servlet
version="2.4.0"
your bundle attempts to use potentially missing classes. It's also possible to control
downstream visibility of packages from a required bundle using the
visibility
direc-
tive, which can be specified as
private
by default or as
reexport
. For example:
Require-Bundle: A; bundle-version="[1.0.0,2.0.0)"; visibility:="reexport"
This makes the required bundle dependency transitive. If a bundle contains this, any
bundle requiring it also sees the packages from bundle A (they're re-exported). Fig-
ure 5.10 provide a pictorial example.
WARNING
There are few, if any, good reasons to use
Require-Bundle
with
reexport
visibility. This mechanism isn't very modular, and using it results in
brittle systems with high coupling.
Now let's return our attention to how
Require-Bundle
supports aggregating split
packages.
5.3.2
Aggregating split packages
Avoiding split packages is the recommended approach in
OSG
i, but occasionally you
may run into a situation where you need to split a package across bundles.
Require-
Bundle
makes such situations possible. Because class searching doesn't stop when a
class isn't found for required bundles, you can use
Require-Bundle
to search for a class
across a split package by requiring multiple bundles containing its different parts.
For example, assume you have a package
org.foo.bar
that's split across bundles A
and B. Here's a manifest snippet from bundle A:
Bundle-ManifestVersion: 2
Bundle-SymbolicName: A
Bundle-Version: 2.0.0
Export-Package: org.foo.bar; version="2.0.0"
Here is a manifest snippet from bundle B:
Bundle-ManifestVersion: 2
Bundle-SymbolicName: B
Bundle-Version: 2.0.0
Export-Package: org.foo.bar; version="2.0.0"
Both bundles claim to export
org.foo.bar
, even though they each offer only half of
it. (Yes, this is problematic, but we'll ignore that for now and come back to it shortly.)