Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

No Format
...
<plugins>
  <plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <extensions>true</extensions>
    <configuration>
      <instructions>
        <Export-Package>org.foo.myproject.api</Export-Package>
        <Private-Package>org.foo.myproject.*</Private-Package>
        <Bundle-Activator>org.foo.myproject.impl1.Activator</Bundle-Activator>
      </instructions>
    </configuration>
  </plugin>
<plugins></plugins>
...

The <Export-Package> and <Private-Package> instructions tell the plugin about the contents of the resulting bundle JAR file. The <Export-Package> instruction tells the plugin which of the available packages to copy into the bundle and to export, while the <Private-Package> instruction indicates which of the available packages to copy into the bundle but not export. If the two sets overlap, as they do in the case, then the export takes precedence. Since we did not specify any values for any other bundle manifest headers, they will assume default values which are described below. One specific behavior to highlight is that the plugin generates the Import-Package bundle manifest header based on the contents of the bundle, which means that you generally do not ever need to explicitly specify it yourself. That's it.

...

No Format
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>my-osgi-bundles</groupId>
  <artifactId>examplebundle</artifactId>
  <packaging>bundle</packaging>    <!-- (1) -->
  <version>1.0</version>
  <name>Example Bundle</name>
  <dependencies>
    <dependency>
      <groupId>org.apache.felix</groupId>
      <artifactId>org.osgi.core</artifactId>
      <version>0.8.0-SNAPSHOT</version>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>    <!-- (2) START -->
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
          <instructions>
            <Export-Package>com.my.company.api</Export-Package>
            <Private-Package>com.my.company.*</Private-Package>
            <Bundle-Activator>com.my.company.Activator</Bundle-Activator>
          </instructions>
        </configuration>
      </plugin>    <!-- (2) END -->
    </plugins>
  </build>
  <repositories>
    <repository>    <!-- (3) START -->
      <id>apache.snapshots</id>
      <name>Apache Snapshot Repository</name>
      <url>http://cvs.apache.org/maven-snapshot-repository</url>
    </repository>   <!-- (3) END -->
  </repositories>
</project>
pluginRepositories>
  <pluginRepositories>
    <pluginRepository>    <!-- (4) START -->
      <id>apache.snapshots</id>
      <name>Apache Snapshot Repository</name>
      <url>http://cvs.apache.org/maven-snapshot-repository</url>
    </pluginRepository>   <!-- (4) END -->
  </pluginRepositories>
</project>

There are four main things to note: (1) the <packaging> specifier There are three main things to note: (1) the <packaging> specifier must be "bundle", (2) the plugin and configuration must be specified (the configuration section is where you will issue instructions to the plugin), and (3) since the plugin is in incubation it is only available in the Apache Snapshot Repository, which must be specified in the set of repositories.the snapshot repository to resolve dependencies (3) and plugins (4). (Note: This repository will change once the 0.8.0-incubator release is available in a repository)

Real-World Example

Consider this more real-world example using Felix' Log Service implementation. The Log Service project is comprised of a single package: org.apache.felix.log.impl. It has a dependency on the core OSGi interfaces as well as a dependency on the compendium OSGi interfaces for the specific log service interfaces. The following is its POM file:

No Format
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.apache.felix</groupId>
  <artifactId>org.apache.felix.log</artifactId>
  <packaging>bundle</packaging>
  <name>Apache Felix Log Service</name>
  <version>0.8.0-SNAPSHOT</version>
  <description>
    This bundle provides an implementation of the OSGi R4 Log service.
  </description>
  <dependencies>
    <dependency>
      <groupId>${pom.groupId}</groupId>
      <artifactId>org.osgi.core</artifactId>
      <version>0.8.0-SNAPSHOT</version>
    </dependency>
    <dependency>
      <groupId>${pom.groupId}</groupId>/groupId>
      <artifactId>org.osgi.compendium</artifactId>
      <artifactId>org<version>0.osgi8.compendium<0-SNAPSHOT</artifactId>version>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
          <instructions>
            <Export-Package>org.osgi.service.log</Export-Package>
            <Private-Package>org.apache.felix.log.impl</Private-Package>
            <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
            <Bundle-Activator>${pom.artifactId}.impl.Activator</Bundle-Activator>
            <Export-Service>org.osgi.service.log.LogService,org.osgi.service.log.LogReaderService</Export-Service>.osgi.service.log.LogReaderService</Export-Service>
          </instructions>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <repositories>
    <repository>
      <<id>apache.snapshots</instructions>id>
      <name>Apache Snapshot <Repository</configuration>name>
      </plugin><url>http://cvs.apache.org/maven-snapshot-repository</url>
    </plugins>repository>
  </build>repositories>
  <repositories><pluginRepositories>
    <repository><pluginRepository>
      <id>apache.snapshots</id>
      <name>Apache Snapshot Repository</name>
      <url>http://cvs.apache.org/maven-snapshot-repository</url>
    </repository>pluginRepository>
  </repositories>pluginRepositories>
</project>

Notice that the <Export-Package> instruction specifies that the bundle exports the Log Service package, even though this package is not contained in the bundle project. By declaring this, the plugin will copy the Log Service package into the resulting bundle JAR file. This is useful in this case because now the bundle can resolve without having to download the entire compendium bundle. The resulting manifest for the Log Service bundle looks like this (notice how the imports/exports automatically have version information associated with them, which was obtained from packageinfo files in the source packages):

...