WARNING: WHEN BND GOES BAD When using bnd, it's essential to inspect
both your bundle contents and your manifest after building, at least while
you're getting started. Small misunderstandings between you and bnd can
Every package in your bundle being exported
All of your dependencies being included in your bundle
None of your classes being repackaged in your bundle
The authors are aware of these possibilities because we've made all of these
mistakes ourselves! You'll quickly discover if your classes haven't been
included in your bundle, but the other two issues may take much longer to
notice; your built bundle will be perfectly valid, but it won't be at all encapsu-
lated, or at all modular, so it's not in the spirit of OSG i.
We've been talking about building using bnd, but what you're doing here is some-
where halfway between building and packaging. The way you're using it, the bnd tool
isn't compiling anything; all it's doing is using the precompiled code to generate a
manifest, and then packaging everything up into a JAR .
When you used bnd to build the fancyfoods.persistence bundle, it added in pack-
age imports, but no versions. Because specifying versions is an OSG i best practice, it
would be annoying if bnd always ignored them. Luckily, bnd will take good care of
your versions if provided with the right information.
Bnd can't guess the version of exported packages from their bytecode, so the ver-
sion must be specified somewhere. One option is to explicitly list the packages in the
Export-Package and provide a version for each one, but this is manual, and undoes
some of the benefits of bnd wildcards. A nicer solution is to make use of bnd's sup-
port for Java package-info.java files. A package-info file is a special class whose
only content is an annotation specifying the version. Because the package-info files
are right next to the source, it's easier to remember to update them when making
An alternative to package-info.java
Some people dislike the extra overhead of maintaining a class to represent information
about their Java packages. As an alternative option, bnd also looks for text files called
packageinfo in each package. These packageinfo files use the properties format,
but otherwise can contain exactly the same information as package-info.java .
Any of the tricks we show you for managing package-info.java will work equally
well in a packageinfo file.
Bnd will automatically detect package-info files and use them to determine the ver-
sion of exported packages. For example, to set the version of the fancyfoods.food
Search WWH ::