The Maven Cookbook

1.7. Starting an Alternative OSGi Framework (Equinox)

1.7. Starting an Alternative OSGi Framework (Equinox)

1.7.1. Task

You want to run your OSGi bundles in Eclipse's Equinox OSGi runtime environment.

1.7.2. Action

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

~/examples/osgi/osgi-project $ mvn pax:provision -Dframework=equinox
[INFO] Scanning for projects...
[INFO] Reactor build order: 
[INFO]   org.sonatype.mcookbook.osgi-project (OSGi project)
[INFO]   osgi-project - plugin configuration
[INFO]   osgi-project - wrapper instructions
[INFO]   osgi-project - bundle instructions
[INFO]   osgi-project - imported bundles
[INFO]   org.sonatype.mcookbook
[INFO] ------------------------------------------------------------------------
[INFO] Building org.sonatype.mcookbook.osgi-project (OSGi project)
[INFO]    task-segment: [pax:provision] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] [pax:provision]
[INFO] Installing /Users/Tim/Library/Code/sonatype/maven-cookbook/mcookbook-examples/osgi/osgi-project/\
       runner/target/pom-transformed.xml to \
       /Users/Tim/.m2/repository/org/sonatype/mcookbook/osgi-project/build/deployment/1.0-SNAPSHOT/\
       deployment-1.0-SNAPSHOT.pom
    ______  ________  __  __
   / __  / /  __   / / / / /
  /  ___/ /  __   / _\ \ _/
 /  /    /  / /  / / _\ \
/__/    /__/ /__/ /_/ /_/

Pax Runner (1.1.1) from OPS4J - http://www.ops4j.org
----------------------------------------------------

 -> Using config [classpath:META-INF/runner.properties]
 -> Using only arguments from command line
 -> Scan bundles from [/Users/Tim/Library/Code/sonatype/maven-cookbook/mcookbook-examples/osgi/osgi-project/\
                       runner/deploy-pom.xml]
 -> Scan bundles from [scan-pom:file:/Users/Tim/Library/Code/sonatype/maven-cookbook/mcookbook-examples/osgi/\
                       osgi-project/runner/deploy-pom.xml]
 -> Provision bundle [mvn:org.apache.felix/org.apache.felix.webconsole/1.2.8, at default start level, bundle \
    will be started, bundle will be loaded from the cache]
 -> Provision bundle [mvn:org.apache.felix/javax.servlet/1.0.0, at default start level, bundle will be \
    started, bundle will be loaded from the cache]
 -> Provision bundle [mvn:org.apache.felix/org.apache.felix.scr/1.0.8, at default start level, bundle will be \
    started, bundle will be loaded from the cache]
 -> Provision bundle [mvn:org.apache.felix/org.apache.felix.http.jetty/1.0.1, at default start level, bundle \
    will be started, bundle will be loaded from the cache]
 -> Provision bundle [mvn:org.sonatype.mcookbook.osgi-project/org.sonatype.mcookbook/1.0-SNAPSHOT, at default \
    start level, bundle will be started, bundle will be loaded from the cache]
 -> Preparing framework [Equinox 3.5.0]
 -> Downloading bundles...
 -> Equinox 3.5.0 : 1122602 bytes @ [ 300kBps ]
 -> Eclipse utilities : 22471 bytes @ [ 64kBps ]
 -> Eclipse compendium services : 66065 bytes @ [ 113kBps ]
 -> Using execution environment [J2SE-1.5]
 -> Runner has successfully finished his job!


osgi> STARTING org.sonatype.mcookbook
REGISTER org.sonatype.mcookbook.ExampleService
org.mortbay.log:Logging to org.mortbay.log via org.apache.felix.http.jetty.LogServiceLog
org.mortbay.log:Init SecureRandom.
org.mortbay.log:started org.mortbay.jetty.servlet.HashSessionIdManager@9ed5d6
org.mortbay.log:started org.mortbay.jetty.servlet.HashSessionManager@fd245f
org.mortbay.log:starting OsgiServletHandler@5f00f9
org.mortbay.log:started OsgiServletHandler@5f00f9
org.mortbay.log:starting SessionHandler@38ef1d
org.mortbay.log:started SessionHandler@38ef1d
org.mortbay.log:starting org.mortbay.jetty.servlet.Context@cc3baa{/,null}
org.mortbay.log:starting ErrorHandler@da6d09
org.mortbay.log:started ErrorHandler@da6d09
org.mortbay.log:started org.mortbay.jetty.servlet.Context@cc3baa{/,null}
org.mortbay.log:jetty-6.1.x
org.mortbay.log:started Realm[OSGi HTTP Service Realm]==[]
org.mortbay.log:started org.mortbay.thread.QueuedThreadPool@f2e41d
org.mortbay.log:starting Server@5e4dbe
org.mortbay.log:started org.mortbay.jetty.nio.SelectChannelConnector$1@9a44d6
org.mortbay.log:Started SelectChannelConnector@0.0.0.0:8080
org.mortbay.log:started SelectChannelConnector@0.0.0.0:8080
org.mortbay.log:started Server@5e4dbe
org.mortbay.log:started /system/console/*
org.mortbay.log:started /system/console/res

Again, the output of this last command is going to be somewhat confusing. Even though we're starting the application using Equinox, we're still deploying some OSGi components from Apache Felix, and we're deploying the Apache Felix Web Management Console. While the Felix Web Management Console can also run in the Equinox OSGi runtime environment, take note that there are some missing classes toward the end of the previous console output. This is likely due to the fact that there is a missing bundle or some Felix-specific functionality that is present in the Felix management console. To test the console, go to http://localhost:8080/system/console, and log in with the default admin/admin credentials.

1.7.3. Detail

For more information about Equinox, see http://www.eclipse.org/equinox/. For more information about the frameworks available to the Pax plugin, see http://paxrunner.ops4j.org/space/Pax+Runner.