Java Reference
In-Depth Information
tell you if you're missing required imports, they won't, in general, flag unused
imports. This means you can end up with bundles with dangerously bloated package
imports, unless you make a point of cleaning up regularly. Maintaining accurate ver-
sions on your exported packages is also almost impossible without some level of byte-
code analysis and partial manifest generation.
Whether you prefer manifest-first or code-first development, one thing is certain:
for projects of any size, you'll need some sort of OSG i-aware tooling. Managing small
manifests by hand is reasonable, but it rapidly becomes impossible without a compiler
to either tell you that you got it wrong or generate the manifest for you.
OSGi and the dreaded ClassNotFoundException
It's often said that OSGi eliminates class-not-found exceptions. This statement
needs to be qualified—OSGi can only eliminate class-not-found exceptions if all the
bundle manifests are correct . A bundle that forgets to import packages is guaranteed
to fail if it tries to use classes from those packages. Both styles of OSGi development
try to guarantee accurate manifests, but a determined developer can introduce man-
ifest errors with either process!
The flagship tool for code-first OSG i development is a command-line tool, bnd. Bnd
is also well integrated into a higher-level stack of more general build tools like Ant
and Maven, and IDE tools. The star tool for manifest-first development, on the other
hand, is Eclipse's built-in OSG i tooling, Eclipse PDE (we'll discuss PDE much more in
chapter 9). Eclipse PDE itself has only limited support for command-line builds, but
several tools integrate with PDE to support command-line building. We'll begin with a
survey of the command-line tools available, starting with bnd.
Building OSGi applications
Although setting up a command-line build may not be the first thing you do when you
start developing a new project, you'll almost certainly need an automated build
sooner or later. Even if you're not wading into build scripts as your first development
step, thinking in advance about what kind of build you want can help you make the
right choices about what kind of IDE tools are best suited for your project.
Your choice of which command-line tools to use will usually be guided by whether
you prefer a manifest-first or code-first style of development. (Alternatively, if you
already know which build tools you want to use, that may make the decision about
manifest-first or code-first for you!) Figure 8.1 shows how the various styles of develop-
ment and tools we'll discuss in this chapter connect to one another.
We'll start our discussion with the bnd tool. If you're sharp-eyed, you'll notice that
bnd only appears in one path in figure 8.1. Nonetheless, if you opt for a code-first style
of OSG i development, you'll almost certainly use either bnd directly or—more likely—
Search WWH ::

Custom Search