Geertjan is a DZone Zone Leader and has posted 459 posts at DZone. You can read more from them at their website. View Full User Profile

How to Run a NetBeans Platform Application as OSGi Bundles

05.18.2010
| 5984 views |
  • submit to reddit

With NetBeans IDE 6.9, not only can you import OSGi bundles into existing NetBeans Platform applications, but you can also convert your entire NetBeans Platform application to a set of OSGi bundles. That is the topic outlined in the article below.

  1. Read the document at http://wiki.netbeans.org/NetBeansInOSGi to find out what you can (and especially what you can't) do with the (currently experimental) mode enabling NetBeans Platform modules to run natively as OSGi bundles.

    The document describes what actually happens to make the OSGi-mode possible: "A small tool (currently available as an Ant task) accepts some NetBeans modules as input - normally a collection of clusters (directories containing modules/*.jar) - and as output produces a collection of OSGi bundles."

    Make sure that you read the document carefully before continuining.

  2. Go to File | New Project and select the "NetBeans Platform Application" template:


  3. Click Next and then provide a name and a location for your new project:


  4. Click Finish, switch to the Files window, and then look at all the files that have been created:

    Redefine the "platform.properties" file as follows, defining the NetBeans Platform clusters named "harness" and "platform" as the only groups of NetBeans modules relevant to the application:

    cluster.path=\
    ${nbplatform.active.dir}/harness:\
    ${nbplatform.active.dir}/platform
    nbplatform.active=default

    Add the following to the "project.properties" file:

    modules=
    branding.token=nb
    felix-sys-prop.org.osgi.framework.system.packages.extra=\
    com.sun.jdi,com.sun.jdi.connect,com.sun.jdi.connect.spi,com.sun.jdi.event,\
    com.sun.jdi.request,sun.awt,sun.misc,com.sun.java.swing.plaf.windows
    osgi.run.cp.extra=\
    ${java.home}/../lib/tools.jar:\
    ${java.home}/../lib/sa-jdi.jar:\
    ${java.home}/../lib/dt.jar
    osgi.run.args=-ea -client -Xss2m -Xms32m -XX:PermSize=32m -XX:MaxPermSize=200m
  5. Right-click the application in the Projects window, find the "OSGi" menu item, and then select the "Run in Felix" submenu:


  6. In the Output window, notice that Felix starts up, deploying the application:


  7. The following application appears:


  8. Several features are provided by default, such as the Favorites window, Output window, and very basic editor support, as shown below:


  9. Return to NetBeans IDE, go to the Files window, expand the "build" folder, and notice that all the erstwhile NetBeans modules in the NetBeans Platform have been converted to OSGi bundles:

Read http://wiki.netbeans.org/NetBeansInOSGi again to answer any questions you might still have.

Published at DZone with permission of its author, Geertjan Wielenga.

Comments

Charles Bedon replied on Sun, 2010/07/18 - 12:15pm

Maybe the question is "Why should I migrate my NBP application to an OSGI application?". The wiki article doesn't say anything about that but "you already have an OSGi-compliant container you are happy with, you have OSGi-oriented development tools (whether based in the NetBeans IDE or not), and you simply want to take advantage of pieces of the NetBeans Platform in your application(...)". The module approach used in NBP works pretty good, and is rather easy to learn, and the Auto Update functionality lets you plug and update new components on the fly too. So I'd say that a good reason to do it is that maybe you want to stick to a [somehow new] industry standard, instead of yet-another-framework (although OSGi is a more general purpose approach technology, not only for desktop aplications), finding support with other IDEs and aligning your client-side development with the server-side which probably use OSGi in depth.
Some benefits from using OSGi can be found here.

Matt Coleman replied on Fri, 2012/02/03 - 12:21am in response to: Charles Bedon

thanks for sharing OSGi benefits...i have learned something new today\ buffalo web design

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.