Java Reference
In-Depth Information
once, run everywhere” goal, because it ties the class to a specific platform. Still, in
those cases where it's absolutely necessary, it's nice to know that
OSG
i supports it.
OSG
i
even simplifies it a little.
One of the downsides of native code is the fact that you end up with an additional
artifact to deploy along with your classes. To make matters worse, what you need to do
with the native library differs among operating systems; for example, you typically
need to put native libraries in specific locations in the file system so they can be found
at execution time (for example, somewhere on the binary search path).
OSG
i native
code support simplifies these issues by
Allowing you to embed your native library directly into your bundle
JAR
file
■
Allowing you to embed multiple native libraries for different target platforms
■
Automatically handling execution-time discovery of native code libraries
■
When you embed a native library into your bundle, you must tell the
OSG
i frame-
work about it. As with all other modularity aspects, you do so in the bundle meta-
data using the
Bundle-NativeCode
manifest header. With this header, you can specify
the set of contained native libraries for each platform your bundle supports. The
grammar is as follows:
Bundle-NativeCode ::= nativecode (',' nativecode)* (',' optional)?
nativecode ::= path (';' path)* (';' parameter)+
optional ::= '*'
The parameter is one of the following:
■
osname
—Name of the operating system
■
osversion
—Operating system version range
■
processor
—Processor architecture
■
language
—
ISO
code for a language
■
selection-filter
—
LDAP
selection filter
For example, if you have a bundle with native libraries for Windows
XP
, you may have
a native code declaration like this one:
Bundle-NativeCode: lib/math.dll; lib/md5.dll; osname=WindowsXP;
processor=x86
This is a semicolon-delimited list, where the leading entries not containing an
=
char-
acter are interpreted as file entries in the bundle
JAR
file and the remaining entries
with an
=
character are used to determine if the native library clause matches the cur-
rent platform. In this case, you state the bundle has two native libraries for Windows
XP on the x86 architecture.
If
Bundle-NativeCode
is specified, there must be a matching header for the plat-
form on which the bundle is executing; otherwise, the framework won't allow the bun-
dle to resolve. In other words, if a bundle with the previous native code header was
installed on a Linux box, the framework won't allow the bundle to be used.