The Maven Cookbook

1.6. Starting an Alternative OSGi Framework (Knopflerfish)

1.6. Starting an Alternative OSGi Framework (Knopflerfish)

1.6.1. Task

You want to run your OSGi bundles in the Knopflerfish OSGi runtime environment.

1.6.2. Action

Pass in the framework configuration parameter when running the pax:provision goal. To start Knopflerfish, run mvn pax:provision -Dframework=kf.

~/examples/osgi/osgi-project $ mvn pax:provision -Dframework=kf
[INFO] Scanning for projects...
[INFO] [pax:provision]
[INFO] Installing ~/examples/osgi/osgi-project/runner/target/pom-transformed.xml to \
[INFO] artifact org.ops4j.pax.runner:pax-runner: checking for updates from central
1067K downloaded  (pax-runner-1.1.1.jar)
    ______  ________  __  __
   / __  / /  __   / / / / /
  /  ___/ /  __   / _\ \ _/
 /  /    /  / /  / / _\ \
/__/    /__/ /__/ /_/ /_/

Pax Runner (1.1.1) from OPS4J -

 -> Using config [classpath:META-INF/]
 -> Using only arguments from command line
 -> Scan bundles from [~/examples/osgi/osgi-project/runner/deploy-pom.xml]
 -> Scan bundles from [scan-pom:file:~/examples/osgi/osgi-project/runner/deploy-pom.xml]
 -> Preparing framework [Knopflerfish 2.3.1]
 -> Downloading bundles...
 -> Knopflerfish 2.3.1 : 366660 bytes @ [ 160kBps ]
 -> org.osgi.compendium : 689150 bytes @ [ 256kBps ]
 -> Knopflerfish Console : 36329 bytes @ [ 55kBps ]
 -> Knopflerfish Console TTY : 6153 bytes @ [ 1538kBps ]
 -> Knopflerfish Framework Commands : 26090 bytes @ [ 158kBps ]
 -> Using execution environment [J2SE-1.5]
 -> Runner has successfully finished his job!

Knopflerfish OSGi framework, version 4.1.3
Copyright 2003-2009 Knopflerfish. All Rights Reserved.

See for more information.
Loading xargs url file:knopflerfish/config.ini
Installed and started: file:bundles/osgi.compendium_4.0.1.jar (id#1)
Installed and started: file:bundles/org.knopflerfish.bundle.console_2.0.1.jar (id#2)
Installed and started: file:bundles/org.knopflerfish.bundle.consoletty-IMPL_2.0.0.jar (id#3)
Installed and started: file:bundles/org.knopflerfish.bundle.frameworkcommands-IMPL_2.0.5.jar (id#4)
Installed and started: file:bundles/org.apache.felix.webconsole_1.2.8.jar (id#5)
Installed and started: file:bundles/org.apache.felix.javax.servlet_1.0.0.jar (id#6)
Installed and started: file:bundles/org.apache.felix.scr_1.0.8.jar (id#7)
Installed and started: file:bundles/org.apache.felix.http.jetty_1.0.1.jar (id#8)
Installed and started: file:bundles/org.sonatype.mcookbook_1.0.0.SNAPSHOT.jar (id#9)
> STARTING org.sonatype.mcookbook
REGISTER org.sonatype.mcookbook.ExampleService
org.mortbay.log:Logging to org.mortbay.log via org.apache.felix.http.jetty.LogServiceLog
Framework launched
org.mortbay.log:Init SecureRandom.
org.mortbay.log:started org.mortbay.jetty.servlet.HashSessionIdManager@b890dc
org.mortbay.log:started org.mortbay.jetty.servlet.HashSessionManager@6321e6
org.mortbay.log:starting OsgiServletHandler@4683c0
org.mortbay.log:started OsgiServletHandler@4683c0
org.mortbay.log:starting SessionHandler@73bc22
org.mortbay.log:started SessionHandler@73bc22
org.mortbay.log:starting org.mortbay.jetty.servlet.Context@a0d346{/,null}
org.mortbay.log:starting ErrorHandler@449afc
org.mortbay.log:started ErrorHandler@449afc
org.mortbay.log:started org.mortbay.jetty.servlet.Context@a0d346{/,null}
org.mortbay.log:started Realm[OSGi HTTP Service Realm]==[]
org.mortbay.log:started org.mortbay.thread.QueuedThreadPool@39491b
org.mortbay.log:starting Server@eea7f0
org.mortbay.log:started org.mortbay.jetty.nio.SelectChannelConnector$1@31db04
org.mortbay.log:Started SelectChannelConnector@
org.mortbay.log:started SelectChannelConnector@
org.mortbay.log:started Server@eea7f0
org.mortbay.log:started /system/console/*
org.mortbay.log:started /system/console/res

The output of this last command is going to be somewhat confusing. Even though we're starting the application using Knopflerfish, we're still deploying some OSGi components from Apache Felix, and we're deploying the Apache Felix Web Management Console. The interesting thing about OSGi: it all still works. The Apache Felix Web Management Console can be used to manage standard OSGi component even when it is running in the Knopflerfish container. To test this, go to http://localhost:8080/system/console, and log in with the default admin/admin credentials. Click on the configuration status tab, and then scroll down to see properties that prove that your Apache Felix web management console is running atop Knopflerfish.

1.6.3. Detail

For more information about Knopflerfish, see For more information about the frameworks available to the Pax plugin, see