Java Reference
In-Depth Information
Bundle-ClassPath: WEB-INF/classes, WEB-INF/lib/velocity-1.4.jar,...
classes
WEB-INF
lib/velocity-1.4.jar
…
…
…
Figure 6.6
Turning a
WAR file into a bundle
and made available to the application by extending the
Bundle-ClassPath
(2.5.3). This
is similar to how Java Enterprise applications are constructed. In fact, you can take an
existing web application archive (
WAR
file) and easily turn it into a bundle by adding an
identity along with
Bundle-ClassPath
entries for the various classes and libraries con-
tained within it, as shown in figure 6.6.
The key benefit of a mega bundle is that it drastically reduces the number of pack-
ages you need to import, sometimes down to no packages at all. The only packages you
may need to import are non-
java.*
packages from the
JDK
(such as
javax.*
packages)
or any packages provided by the container itself. Even then, you can choose to access
them via
OSG
i boot delegation by setting the
org.osgi.framework.bootdelegation
framework property to the list of packages you want to inherit from the container class
path. Boot delegation can also avoid certain legacy problems (see section 8.2 for the
gory details). The downside is that it reduces modularity, because you can't override
boot-delegated packages in
OSG
i. A mega bundle with boot delegation enabled is close
to the classic Java application model; the only difference is that each application has its
own class loader instead of sharing the single
JDK
application class loader.
JEDIT MEGA-BUNDLE EXAMPLE
Let's shelve the theoretical discussion for the moment and create a mega bundle
based on jEdit (
www.jedit.org/
), a pluggable Java text editor. The sample code for this
topic comes with a copy of the jEdit 4.2 source, which you can unpack like so:
$
cd chapter06/jEdit-example
$
ant jEdit.unpack
$
cd jEdit
The jEdit build uses Apache Ant (
http://ant.apache.org/
)
, which is good news because
it means you can use bnd's Ant tasks to generate
OSG
i manifests. Maven users shouldn't
feel left out, though: you can use maven-bundle-plugin (
http://felix.apache.org/site/
apache-felix-maven-bundle-plugin-bnd.html
)
, which also uses bnd under the covers.
How exactly do you add bnd to the build? The following listing shows the main tar-
get from the original (non-
OSG
i) jEdit build.xml.
Listing 6.1 Default jEdit build target
<target name="dist" depends="compile,compile14"
description="Compile and package jEdit.">
<jar jarfile="jedit.jar"