Component-based development

Eclipse and OSGi


  • comparing Eclipse Extension Registry to OSGi services
  • describing Declarative Services in OSGi as the best of both worlds

  • lightweight OSGi container
  • hot-deployment
  • SSH access

  • totorial about bndtools
  • automates development with OSGi, e.g. declarative services
  • Bndtools follows the “generated manifest” approach to building OSGi bundles; this is in contrast to the “manifest first” approach used by some other tools.

  • BND annotations explained
  • @Component, @Activate, @Deactivate, @Reference ...

  • OSGi Lite = 80% functionality of OSGi
  • without module boudaries, in a single class loader

  • Annotation processor for OSGi Declarative Service Components
  • supports BND annotations and RFC0172 annotations
  • generates XML files in OSGI-INF
  • Eclipse plugin

  • Bundle Plugin for Maven

  • getting command line arguments from BundleContext when using BND-annotations + DS

  • about services (e.g. immediate vs delayed) ...

  • dynamic loading/unloading of bundles and configurations from a directory

Tips for OSGi development

  • use bndtools plugin for Eclipse
  • use "name.njbartlett.osgi.emf" project for EMF support in non-Eclipse applications
  • Import some bundles from your running eclipse plugins/ dir to the "local repository" located in the "cnf" project of your workspace (use the "Repositories" view for importing)
  • Most of your projects will contain multiple bundle descriptors (*.bnd) files.
  • Make sure you set "Declarative Services: Bnd Annotations" in all bundle descriptors where you have classes annotated with the @Component annotation.
  • To define a component X which provides an interface Y, use:
 class X implements Y { ... }
  • To define a component X which just provides itself, use:
 class X { ... }
  • To define a required interface XYZ, use
 void setXYZ(XYZ instance) { ... }
  • You can make the binding dynamic, i.e. your component will be notified about updates after it has started:
  • You can define a component that gets instantiated for each bundle separately. However, if there are multiple consumers within the same bundle, they share the instance.
 class X implements Y { ... }
  • You can define a component that can be dynamically created multiple times using a factory.
 // these instances will be created by the factory
 class X implements Y { ... }

 // this component uses the factory
 class Consumer {

   private ComponentInstance comp;

   @Reference(target = "(component.factory=MYNAME)")
   public void setFactory(final ComponentFactory factory) {
     // remember the component to control its lifecycle
     // or use it to create instances
     comp = factory.newInstance(properties);
     final Y serviceY = (Y) comp.getInstance();

   void deactivate() {
  • By default, bnd generates the bundles that include the original source code from the project. To disable bundling of the source code, add the following line to the bnd.bnd file:
 -sources: false
  • In order to preserve service configurations between OSGi restarts, add the following line to your *.bndrun file. If you don't do that, bndtools will use the generated/fw dir which is cleaned before running OSGi from a *.bndrun file.
 -runproperties: \
  • To activate the web console, add the following bundles to the "Run Requirements". You can then visit http://localhost:8080/system/console/configMgr (username=admin, password=admim) and change the configuration settings of your components.

Model-driven development

OCL (Object Constraint Language)

Tips and Tricks