Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to Run a NetBeans Platform Application as OSGi Bundles

DZone's Guide to

How to Run a NetBeans Platform Application as OSGi Bundles

· Java Zone
Free Resource

What every Java engineer should know about microservices: Reactive Microservices Architecture.  Brought to you in partnership with Lightbend.

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.

Microservices for Java, explained. Revitalize your legacy systems (and your career) with Reactive Microservices Architecture, a free O'Reilly book. Brought to you in partnership with Lightbend.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}