logo.pngThis is the second step in a series of items about exploring the felix osgi container and some sidesteps to make life easier while developing osgi bundles. You can find the first step here: http://www.gridshore.nl/2008/02/10/starting-with-osgi-using-apache-felix-step-1/

This is so easy, I do not want to spend to much time here. There is a special maven 2 plugin to create a “bundle”, check out the following page that describes the plugin : maven-bundle-plugin.

Create a new maven project using the most basic archetype.

mvn archetype:create -DgroupId=<your.groupid> -DartifactId=<your.artifactId>

Change the packaging of the pom to be "bundle". Add a dependency to the core and configure the plug in. The possible parameters are described extensively at the mentioned web page. I’ll explain the what and why of the code below, not the theory. The following pom file is the pom of the project example-client in the FelixTryout project on my google code page. As you can see there is a dependency on the training-service and on jetty. i am not going to talk about jetty here. More on that in one of the next steps.

<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">

The export-package contains the packages that are exposed to other bundles. This results in the following manifest file:

Manifest-Version: 1.0
Built-By: jettro
Created-By: Apache Maven Bundle Plugin
Bundle-Activator: nl.gridshore.samples.bundles.exampleclient.impl.Acti
Import-Package: javax.servlet;version="2.5",javax.servlet.http;version
Bnd-LastModified: 1202823580612
Bundle-Version: 1.0.0.SNAPSHOT
Bundle-Name: example-client
Build-Jdk: 1.5.0_13
Private-Package: nl.gridshore.samples.bundles.exampleclient.impl
Bundle-ManifestVersion: 2
Bundle-SymbolicName: example-client
Tool: Bnd-0.0.227

Most of the items are pretty obvious if you look at the maven configuration. There is one thing that is more advanced. Have a look at the import-Package, this contains the packages that are imported by the classes. This is done automatically by the bundle plugin. You can prevent imports by configuring the "ImportPackage" and use the negative import.


That is about it, mvn clean install and your plugin is installed into the maven repository. Well, of course you do need to implement some java code. Just like I said before, you can find the implementation on google code. I will also introduce the concepts in the forthcoming steps or posts.

Tagged on:             

2 thoughts on “Using maven to create an osgi bundle (osgi felix sample step 2)

  • July 29, 2009 at 5:52 pm

    Not sure anymore, it has been a while. But there are multiple resources available. I know felix has it’s own repository, spring source has one. And lot’s of other provide bundles.

  • July 29, 2009 at 3:52 pm

    Could you let me know which repositories (repository and/or pluginRepository) do you use, please?



Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>