Apache
Home » Documentation » Apache Felix Commons

Creating Bundles Using BND

Purpose

Provide the list of steps required to create a library bundle by wrapping the library jar using bnd (http://bnd.bndtools.org/).

Steps
  1. Use bnd to analyze the library jar (e.g., java -jar bnd-0.0.jar print path/to/FOO.jar)
  2. At the bottom of the bnd output, look for "Unresolved references to ..." which identify package dependencies. If found, a. Identifiy the library jars that provide the missing packages b. Recursively use this process on each dependency
  3. Create a directory that will be the project directory for the bundle (e.g., mkdir FOO-osgi)
  4. Copy the template pom.xml file to the bundle's project directory
  5. Edit the pom.xml file to tailor it for the library jar. Specifically, a. change artifactId b. verify description c. change version d. change FOO's library jar dependency (groupId, artifactId) e. add any other dependencies (from step 2b) f. change Export-Package g. change Private-Package or delete it if it's not needed h. All packages listed in step 1 should be in either Export-Package or Private-Package. Use the library's javadoc to identify the exported packages. The remaining packages should be private.
  6. Run "mvn package" to in the project directory to create the bundle
  7. Use bnd to verify the bundle's contents (e.g., java -jar bnd-0.0.jar print target/FOO-osgi-VERSION.jar)
  8. Run "mvn install" to install the bundle in the local repository
Example POM
<project
  xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <groupId>org.apache.felix.commons</groupId>
  <artifactId>FOO-osgi</artifactId>
  <name>${pom.artifactId} bundle</name>
  <description>
    This bundle simply wraps FOO-${pom.version}.jar.
  </description>
  <version>X.Y</version>
  <packaging>bundle</packaging>

  <organization> 
    <name>Apache Felix Project</name> 
    <url>http://felix.apache.org/</url> 
  </organization>

  <dependencies>
    <dependency>
      <groupId>FOO</groupId>
      <artifactId>FOO</artifactId>
      <version>${pom.version}</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
          <instructions>
            <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
            <Export-Package>FOO</Export-Package>
            <Private-Package>FOO.impl</Private-Package>
          </instructions>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>
Resources

Bnd - Bundle Tool http://bnd.bndtools.org/

Bundle Plugin for Maven http://felix.apache.org/site/maven-bundle-plugin-bnd.html

Rev. 1762306 by cziegeler on Mon, 26 Sep 2016 09:54:12 +0000
Apache Felix, Felix, Apache, the Apache feather logo, and the Apache Felix project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.