Getting started with OSGi on Apache Felix


To work with OSGi modules (or bundles), you’ll have to use, I let you guess …, an OSGi container. There a few open source containers including Apache Felix and Eclipse Equinox. The first one is used in application such as Glassfish v3, Service Mix 4, … and the second one in … Eclipse IDE of course.

Let’s start with downloading Apache Felix here and choose Felix Framework Distribution 3.0.3.

Unzip it and run the container (felix-framework-3.0.3/bin/felix.jar) with :

java -jar bin/felix.jar

You’ll have a g! prompt (fore felix console “gogo”) where you can enter the help command :

____________________________
Welcome to Apache Felix Gogo

g! help
felix:bundlelevel
felix:cd
felix:frameworklevel
felix:headers
felix:help
felix:inspect
felix:install
felix:lb
felix:log
felix:ls
felix:refresh
felix:resolve
felix:start
felix:stop
felix:uninstall
felix:update
felix:which
gogo:cat
gogo:each
gogo:echo
gogo:format
gogo:getopt
gogo:gosh
gogo:grep
gogo:not
gogo:set
gogo:sh
gogo:source
gogo:tac
gogo:telnetd
gogo:type
gogo:until
obr:deploy
obr:info
obr:javadoc
obr:list
obr:repos
obr:source
g!

List installed bundle

g! felix:lb
START LEVEL 1
 ID|State      |Level|Name
 0|Active     |    0|System Bundle (3.0.3)
 1|Active     |    1|Apache Felix Bundle Repository (1.6.2)
 2|Active     |    1|Apache Felix Gogo Command (0.6.1)
 3|Active     |    1|Apache Felix Gogo Runtime (0.6.1)
 4|Active     |    1|Apache Felix Gogo Shell (0.6.1)

Install bundles

g! felix:install file:bundle/helloworld.jar
Bundle ID: 18

Start installed bundles

g! felix:start 18
Hello World!

Stop Apache Felix

felix:stop 0

Don’t be surprised next time you launch Apache Felix, installed bundles will automatically be reloaded thanks to felix-cache.

To continue …

Advertisements

NetBeans 6.9 and OSGi

Netbeans 6.9 integrates the OSGi interoperability. In fact, you can create OSGi bundles to use in Java applications.

It also enables you to build OSGi bundles from a Maven archetype and then access the bundles from applications that are running in an OSGi container.

  • Develop OSGi bundles with Maven
  • Bundled Felix container
  • Use OSGi bundles in a NetBeans RCP application

Likewise, NetBeans 6.9 offers the support for JavaFX 1.3.1, Spring Framework 3.0 library, PHP Zend Framework, …

You can download the 6.9.1 version it here. And here are the feature Higlights.