« Back to home

OSGI "Hello World" with Eclipse Luna

If you follow a simple tutorial to set up an OSGI project, there’s a good chance that running your project will cause the console window to fill up with errors and backtraces.

The root cause seems to be that by default, Eclipse assumes that your OSGI bundle wants to run inside a complete Eclipse runtime. So when you choose Run, Eclipse tries to run your bundle inside another instance of Eclipse running inside Eclipse. This doesn’t work very well.

To get a simple “Hello world” plugin running, you need to edit the run configuration (via Run > Run Configurations...) and uncheck everything on the Bundles tab under “Target Platform” except the bundles you plan to use. Typically that’s these five:

  1. org.apache.felix.gogo.runtime
  2. org.apache.felix.gogo.shell
  3. org.apache.felix.gogo.command
  4. org.eclipse.equinox.console
  5. org.eclipse.osgi

Then on the Settings tab, you need to check the box that says “Clear the configuration area before launching”, so Eclipse will actually remove previous cached configuration information and only load the plugins you ask it to load.