Something I have always lamented about OSGi is a lack of simple examples to get up and running quickly. So here is a simple example using Groovy:

First, dependencies are easily added via Maven, adding the following to your pom.xml should do it.












Then a simple Groovy script to start the OSGi framework and print a message.

import org.osgi.framework.BundleActivator

import org.osgi.framework.BundleContext

import org.osgi.framework.launch.Framework

import org.osgi.framework.launch.FrameworkFactory

FrameworkFactory osgiFactory = ServiceLoader.load(FrameworkFactory).find()

def configMap = ['felix.systembundle.activators': [new BundleActivator() {

	void start(BundleContext context) throws Exception {

		println "System bundle started"


	void stop(BundleContext context) throws Exception {

		println "System bundle stopped"



Framework osgi = osgiFactory.newFramework(configMap)

System.addShutdownHook {

	println "Shutting down"

	try {




	catch (Exception e) {






osgi.bundleContext.bundles.each {

	println "$it.bundleId $it.symbolicName $it.state"



Of course you need to load some bundles to do something useful, but this demonstrates that it isn’t actually that hard to create an embedded OSGi runtime with a custom System Bundle Activator for accessing services from other bundles.