Java Reference
In-Depth Information
CUTTING ALONG THE DOTTED LINES
Returning to the jEdit example, what areas suggest themselves as potential bundles?
The obvious choice to begin with is to separate the jEdit code from third-party librar-
ies and then try to extract the main top-level package. But how do you go about divid-
ing the project class path into different bundles?
Recall what we said about bnd back in section 6.1.3, that it uses a pull approach to
assemble bundles from a project class path based on a list of instruction files. All you
need to do is provide your bnd task with different instruction files for each bundle.
The following example divides the class path into three bundles:
<bnd classpath="${build.directory}"
files="jedit-thirdparty.bnd,jedit-main.bnd,jedit-engine.bnd" />
The first bundle contains all third-party classes—basically, any package from the build
directory that doesn't start with org.gjt.sp . Bnd makes this easy by allowing negated
packages. For example:
Private-Package: !org.gjt.sp.*, *
This copies all other packages into the bundle and keeps them private.
Using the earlier jedit-mega.bnd file as a template, you can flesh out the rest to get
the following jedit-thirdparty.bnd file:
-output: jedit-thirdparty.jar
Bundle-Name: jEdit Third-party Libraries
Bundle-SymbolicName: org.gjt.sp.jedit.libs
Bundle-Version: 4.2
Private-Package: !org.gjt.sp.*, !installer.*, *
You also exclude the installer package because it isn't required at execution time
and doesn't belong in the third-party library bundle.
The second bundle contains the top-level package containing the main jEdit class.
You should also add the org.gjt.sp.jedit.proto package containing the URL han-
dler code because it's only used by the bundle activator in the top-level package.
Here's an initial attempt at jedit-main.bnd:
-output: jedit.jar
-include: org/gjt/sp/jedit/jedit.manifest
Bundle-Name: jEdit
Bundle-SymbolicName: org.gjt.sp.jedit
Bundle-Version: 4.2
Private-Package: org.gjt.sp.jedit, org.gjt.sp.jedit.proto.*
Bundle-Activator: org.gjt.sp.jedit.Activator
Notice that the only difference between this file and the mega bundle instructions
shown earlier is the selection of private packages; everything else is exactly the same.
The main bundle also replaces the mega bundle as the executable JAR file.
Search WWH ::




Custom Search