DUE TO SPAM, SIGN-UP IS DISABLED. Goto Selfserve wiki signup and request an account.
...
| 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-incubator</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.m2.incubator</id>
<name>Apache M2 Incubator Repository</name>
<url>http://people.apache.org/repo/m2-incubating-repository/</url>
</repository> <!-- (3) END -->
</repositories>
<pluginRepositories>
<pluginRepository> <!-- (4) START -->
<id>apache.m2.incubator</id>
<name>Apache M2 Incubator Repository</name>
<url>http://people.apache.org/repo/m2-incubating-repository/</url>
</pluginRepository> <!-- (4) END -->
</pluginRepositories>
</project>
|
There are four two main things to note: (1) the <packaging> specifier must be "bundle" , and (2) the plugin and configuration must be specified (the configuration section is where you will issue instructions to the plugin), and the snapshot repository to resolve dependencies (3) and plugins (4instructions to the plugin).
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-incubator</version>
</dependency> implementation of the OSGi R4 Log service.
</description>
<dependencies>
<dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>org.osgi.compendium<core</artifactId>
<version>0.98.0-incubator-SNAPSHOT<incubator</version>
</dependency>
</dependencies>
<build><dependency>
<plugins>
<plugin><groupId>${pom.groupId}</groupId>
<groupId>org<artifactId>org.apacheosgi.felix<compendium</groupId>artifactId>
<artifactId>maven-bundle-plugin</artifactId><version>0.9.0-incubator-SNAPSHOT</version>
</dependency>
<extensions>true<</extensions>dependencies>
<build>
<configuration><plugins>
<instructions><plugin>
<Export-Package>org.osgi.service.log</Export-Package>
<groupId>org.apache.felix</groupId>
<Private-Package>org.apache.felix.log.impl</Private-Package>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
<configuration>
<Bundle-Activator>${pom.artifactId}.impl.Activator</Bundle-Activator><instructions>
<Export-Service>orgPackage>org.osgi.service.log.LogService,org.osgi.service.log.LogReaderService<log</Export-Service>Package>
</instructions>
</configuration> <Private-Package>org.apache.felix.log.impl</Private-Package>
</plugin>
</plugins>
<Bundle-SymbolicName>${pom.artifactId}</build>Bundle-SymbolicName>
<repositories>
<repository>
<id>apache.m2.incubator</id><Bundle-Activator>${pom.artifactId}.impl.Activator</Bundle-Activator>
<name>Apache M2 Incubator Repository</name>
<url>http://people.apache.org/repo/m2-incubating-repository/</url><Export-Service>org.osgi.service.log.LogService,org.osgi.service.log.LogReaderService</Export-Service>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>apache.m2.incubator</id></instructions>
<name>Apache M2 Incubator Repository<</name>configuration>
<url>http://people.apache.org/repo/m2-incubating-repository/</url>plugin>
</pluginRepository>plugins>
</pluginRepositories>build>
</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):
...
The plugin is hosted at the Apache Felix incubator project. The following steps describe how to build and install the plugin into your local Maven2 repository.
...
| No Format |
|---|
$ svn co http://svn.apache.org/repos/asf/felix/trunk/tools/maven2/maven-bundle-pluginbundleplugin |
Using Maven2, build and install the maven-bundle-plugin by issuing the following Maven2 command in the project directory that was created as a result of the previous step.
...
The maven-bundle-plugin also provides various additional functionality via some new Maven goals. Command-line execution of a goal is performed as follows:
...
There are also new instructions available from the underlying BND tool, which continues to be improved independently; for the latest see http://aqute.biz/Code/Bnd BND documentation.
The default goal bundle will be initialized by setting the <packaging> entry to "bundle".
...