Prev Next

Using bnd Workspace Projects from Maven Projects

In this section we create a Maven project and consume the API from the previous section of this tutorial.

Build a Maven Project

You should now create a Maven (not a Bndtools) project. Let’s call this project osgi.enroute.examples.eval.provider. Just use the most simplest Maven project you can find (you can select this at the first wizard page). It provides the implementation of the API we defined in the Bndtools osgi.enroute.examples.eval.api project.

The groupId should be osgi.enroute.examples and the artifactId to the customary Bundle Symbolic Name: osgi.enroute.examples.eval.provider. Let’s use a snapshot version: 1.0.0-SNAPSHOT. The prolog of the pom.xml file should look like:

<project xmlns="" xmlns:xsi=""

We are going to implement the Eval API with parsii external dependency. We also need the OSGi component annotations and of course our API. So our dependencies section in the POM should look like:


We want to build this project with the bnd Maven plugin, so we need to add the following build section:


Instructions for bnd

Last, but not least, we need to provide an adjacent bnd.bnd file, we need to export the API package and we want to include the parsii JAR because it happens to be not a bundle. We do not have to wrap the Guava library because it is a proper bundle. We assume this will be linked in through the application we develop later.

Export-Package: 	osgi.enroute.examples.eval.api
Private-Package: 	parsii.*
-sources: 			true

Note that the Maven plugin by default includes all the classes in the project.

Source Code

The source code in src/main/java/ is:

package osgi.enroute.examples.eval.provider;

import java.util.List;

import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;

import osgi.enroute.examples.eval.api.Eval;
import parsii.eval.Expression;
import parsii.eval.Function;
import parsii.eval.Parser;
import parsii.eval.Scope;

public class EvalImpl implements Eval {
	Scope scope = new Scope();

	public double eval(String expression) throws Exception {
		Expression expr = Parser.parse(expression);
		return expr.evaluate();


If you’ve done everything well (and we as well) then your project should be buildable from the command line:

mvn install
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.247 s
[INFO] Finished at: 2016-04-08T19:17:48+02:00
[INFO] Final Memory: 13M/309M
[INFO] ------------------------------------------------------------------------


We’ve now a relatively unmanaged situation. In the current setup, Bndtools will install every JAR it builds immediately in the local Maven repository. However, Maven will not pick this up automatically. You will have to update the classpath manually. However, this is in general what Maven users are used to?

What We’ve Done

We now build a standard Maven project that has a dependency on a Bndtools project. The Bndtools project will be updated (‘installed’) every time when there is a change.

In the next section we take a look at how we can depend on this Maven project.

Prev Next