Java Reference
In-Depth Information
6.2.4
To bundle or not to bundle?
Sometimes, you should take a step back and think, do I need another bundle? The more
bundles you create, the more work is required during build, test, and management in
general. Creating a bundle for every individual package is obviously overkill, whereas
putting your entire application inside a single bundle means you're missing out on mod-
ularity. Some number of bundles in between is best, but where's the sweet spot?
One way to tell is to measure the benefit introduced by each bundle. If you find
you're always upgrading a set of bundles at the same time and you never install them
individually, keeping them as separate bundles isn't bringing much benefit.
You can also look at how your current choice affects developers. If a bundle layout
helps developers work in parallel or enforces separation between components, it's
worth keeping. But if a bundle is getting in the way of development, perhaps for leg-
acy class-loader reasons, you should consider removing it, either by merging it with an
existing bundle or by making it available via boot delegation (we briefly discussed this
option at the start of section 6.2.1). Consider the jEdit example: have you reached the
right balance of bundles?
A BUNDLE TOO FAR
Let's refresh your memory. Recall the Import-Package discussion back in the section
“Stitching the pieces together.” We mentioned an interesting issue caused by placing
the top-level package in its own bundle, separate from the rest of the jEdit engine. You
can see the problem for yourself by starting the OSG i version of jEdit and selecting
File > Print. A message box pops up (see figure 6.12), describing a failure in a Bean-
Shell script.
Why did the script fail? The error message suggests a class-loading problem. If you
scroll down through the stack trace, you'll notice the last jEdit class before the call to
bsh.BshMethod.invoke() is org.gjt.sp.jedit.BeanShell . This is a utility class that
manages BeanShell script execution for jEdit. It's part of the top-level jEdit package
loaded by the main bundle class loader, and it configures the BeanShell engine to use
a special instance of JARClassLoader (previously discussed in section 6.2.3) that
Figure 6.12 Error attempting to print from jEdit
Search WWH ::




Custom Search