Recent Changes - Search:

Research


edit SideBar


OSGiNetBeans

OSGi bundles + NetBeans

I created this tutorial, because I had some problems findig a good solution for creating OSGi bundles.

First step is to choose OSGi implementation. There are two free implementations: OSCAR (http://oscar.objectweb.org/) and Knopflerfish (http://www.knopflerfish.org/). I chose Knopflerfish because it seemed a bit more programmer friendly. But OSCAR is also OK.

Second step is to choose IDE. There is an Eclipse plugin available for Knopflerfish (http://www.knopflerfish.org/eclipse_plugin.html). It worked fine with simple bundles, but I failed to use it for more complex bundles like a servlet. It might be not the fault of the plugin. I'm new to Eclipse and OSGi development, so I had several problems with both. Finally I turned back to NetBeans and used its great ant-based build system and Knopflerfish' example ant scripts.

Before creating a new project:

NetBeans needs bcel to compile bundles: http://jakarta.apache.org/bcel Download it and copy bcel-<version>.jar into the ant directory of NetBeans: <Netbeans_installdir>/ide6/ant/lib

The KF project has defined a custom Ant task for automatic creation bundle manifest. The task need to be compiled.

Compile BundleInfoTask with NetBeans:

  • create a new free-form project in NetBeans (File/New Project/General/New Java Project with Existing Ant script)
  • In the Built Script field add <knopflerfish install dir>/ant/bundletasks.xml
  • Run the default target in the IDE (Right click on the XML file, Run target, default)

Compile BundleInfoTask with Ant: If you have experience with Ant you can compile the sources in <knopflerfish install dir>/ant/src with help of the buildtasks.xml file.

Create a new project:

Default example script of Knopflerfish failed to compile my simple HelloWorld bundle although I followed the instructions presicely. Finally I created my own ant script based on the example script and built_impl.xml of Knopflerfish.

These are the steps:

  • create your source directory in <knopflerfish install dir>/osgi/bundles/<your project>/src
  • copy build.xmlΔ to <knopflerfish install dir>/osgi/bundles/<your project>
  • create a new free-form project in NetBeans (File/New Project/General/New Java Project with Existing Ant script)
  • specify source directory, build.xml, name of project and location of project files
  • set jar_impl ant target for Build Project action and clean target for Clean
  • add path of libraries you want to use to Classpath (it is needed for correct code completion and error cheching of the editor in NetBeans)
  • Modify build.xml:
    • set the name of the project
    • see <!-- Project specific part --> ... <!-- End of project specific part --> for project specific settings like bundle data
    • don't forget to add path of libraries to bundle.compile.path

Modify topdir and proj.dir only if you did _not_ created your source in <knopflerfish install dir>/osgi/bundles/<your project> or your build.xml is not in this folder. (topdir should be the install directory of Knopflerfish, proj.dir should be your project directory containing src folder).

If everything go fine, jar file of your implementation should be in <knopflerfish install dir>/osgi/jars/<your project>/<your project>-<version>.jar and can be installed by: framework install file:jars/<your project>/<your project>-<version>.jar command in Knopflerfish command shell.

If you want to modify output dir or other compile and build settings like name of source directory or jar file, see <!-- Settings --> part of the script.

Future work:

  • create jar_api and jar_all targets
  • maybe create plugin for NetBeans to make life easier

Contact:

Somogyi Erzsebet, rzso[at]impulzus.sch.bme.hu

Edit - History - Print - Recent Changes - Search
Page last modified on November 19, 2006, at 07:18 PM EST