Prev Next

Assembling an Application in Bndtools

The goal of this section is to create a bndrun file for an application that depends on the Maven Eval provider project. We want to assemble this application with the resolver. This requires that our Maven Bnd Repository is also an OSGi repository. We need to set this up because this is not automatically the case.


As application, let’s create a minimal Gogo command that calls the Eval service.

For this, create the osgi.enroute.examples.eval.application project. The template turns this into a full blown web application so you can throw away the following directories:


This generates some errors in the bnd.bnd file, just get rid of the -includeresource instruction that included those directories.

You can add the following source code:

package osgi.enroute.examples.eval.gogo;

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

import osgi.enroute.debug.api.Debug;
import osgi.enroute.examples.eval.api.Eval;

 * This is the implementation. It registers the Gogo interface and calls it
 * through a Gogo command.
@Component(service=EvalCommand.class, property = { Debug.COMMAND_SCOPE + "=eval",
		Debug.COMMAND_FUNCTION + "=expr" }, name="osgi.enroute.examples.eval.gogo")
public class EvalCommand {
	private Eval target;

	public Object expr(String message) throws Exception {
		return target.eval(message);


This implements the eval:expr command.


We now have to create a runtime environment where we have the following parts:

  • The Gogo command/application bundle (In the Workspace)
  • Gogo (In the OSGi enRoute Distro repository)
  • The provider we created in the Maven project

The first entries are in our repositories but the last entry is so far invisible to us. Since this project is only locally available we need to make it available in the Local repository. We do this by editing the ./cnf/local.mvn file. We add the coordinates of the Maven project:


This will make it available in the Repositories view.


We can now double click on the osgi.enroute.examples.eval.bndrun file in the osgi.enroute.examples.eval.application project. We can now drag the requirements from the repositories to the Run Requirements list in the usual fashion. Make sure the application is added to the initial requirements. You should also add the Gogo shell ( Although the application project provides a Gogo command, it does not have a dependency on Gogo.

If you resolve then you get the following bundles (or similar):

-runbundles \

We can now run the command by clicking on the Debug icon at the top right:

   ___ _ __ |  _ \ ___  _   _| |_ ___ 
  / _ \ '_ \| |_) / _ \| | | | __/ _ \
 |  __/ | | |  _ < (_) | |_| | |_  __/
  \___|_| |_|_| \_\___/ \__,_|\__\___|
G! eval:expr "1 + sqrt(4)"

Prev Next