Efficient way of building an OSGi distribution with maven

152 Views Asked by At

First of all, I'm a beginner with OSGi/Maven and I am studying how can I work efficiently with these tools (for the moment, I forecast to use Felix as my OSGi implementation)

I would like to create a project based on many bundles. Of course, every-time I make a modification on one (or many) of my bundle(s), I do not want to redeploy "manually"

What I would like to do is something like:

mvn buildMyOsgiDistrib
mvn runMyOsgiDistrib

What do you suggest me? Thanks

2

There are 2 best solutions below

1
On

Thank you very much Christian for this detailed answer

Since I posted my question, I found the following documentation Cooking with Maven and OSGi, based on the Maven Pax Plugin

It offers the advantage to work on any OSGi implementation (not only Karaf). For the moment I am studying what this option...

Once again, thank you very much

0
On

There are two options that can get you there.

You can either:

Use Apache Karaf and create a custom distribution

You create a karaf feature file in one project and use the karaf-maven-plugin to create a custom karaf distro.

See this example https://github.com/cschneider/decanter-docker/blob/master/decanter-server/pom.xml .

Use bndtools to assembly your application.

In this case you create a pom with your dependencies and use the bnd-indexer-plugin to create an OBR index from it.

Then you can use a bndrun file in standalone mode to define your top level dependencies and let the resolver resolve them against the repo you created above.

I created a maven plugin to automate the resolve and export step that is normally executed in bndtools UI. This plugin will likely be part of the next bnd release.

See the osgi-chat example.

The karaf variant is more proven as it exists for longer already but karaf is not plain felix. The advantage of karaf is that it has a lot of features for typical bigger projects. So it is easier to get this working.

The bndtools variant is not as established as they just started supporting maven. You also have to include all dependencies yourself in the pom for the index. The positive aspects are that it creates a very small deployable and the resolver helps you a lot to get your dependencies right.