Java Reference
In-Depth Information
Listing 8.1
The bnd.bnd file for building the fancyfoods.persistence JAR
Bundle-Name: Fancy Foods Persistence Bundle
Bundle-SymbolicName: fancyfoods.persistence
Bundle-Version: 1.0.0
Private-Package: fancyfoods.persistence
Import-Package: *
This is almost exactly the same as the manifest you wrote in chapter 3. One little dif-
ference is that the bnd file is parsed as a properties file, so line breaks must be escaped
with a backslash, rather than indenting the following line with a space. But the two
most important differences are the extra header, Private-Package: , and that you're
allowed to use the value * for pattern matching.
Private-Package: is used to indicate that a package should be considered private
to the bundle, and that it should not be exported. Bnd will assume that any code not
mentioned in a standard Export-Package: or bnd-specific Private-Package: header
should be ignored; bnd won't put code into the bundle it builds unless you explicitly
tell it to do so. This may surprise you the first time you do a bnd-based build.
Even though there are three of them, getting all the package declarations right
isn't as time consuming as you might initially guess, because of the second difference
between the bnd file and a manifest— patterns. Notice how listing 8.1 uses a wildcard
for the package imports. You can also use wildcards and other regular expression con-
structs such as ! , when setting your private and exported packages.
To see how the bnd file works, let's get bnd to produce the fancyfoods.persistence
bundle. Navigate to the folder that contains the compiled fancyfoods.persistence
classes and create the bnd.bnd file (or the folder with your Eclipse .classpath folder if
you imported fancyfoods.persistence into Eclipse). (If you name the file fancy-
foods.persistence.bnd , bnd will automatically work out the bundle symbolic name
and JAR name.) Then type the following
java -jar ${bnd.path}/biz.aQute.bnd.jar buildx -classpath
${bin.dir} bnd.bnd
where ${bin.dir} is the location of the compiled fancyfoods.persistence classes. If
you have the fancyfoods.persistence bundle set up as an Eclipse project, you can
use the following command from the root of the Eclipse project:
java -jar ${bnd.path}/biz.aQute.bnd.jar bnd.bnd
Bnd will create a fancyfoods.persistence.jar file in the current directory. Open it
up and have a look at what classes were included and the manifest. You'll see that
bnd has helpfully included what the Private-Package: header looked like after
wildcard expansion. It's also added in required manifest headers like the Bundle-
ManifestVersion .
Search WWH ::

Custom Search