Over a million developers have joined DZone.

From NetBeans Modules to OSGi and Back!

DZone's Guide to

From NetBeans Modules to OSGi and Back!

· Java Zone ·
Free Resource

Get the Edge with a Professional Java IDE. 30-day free trial.

The big blocker for some in relation to the NetBeans Platform is its lack of OSGi support. OSGi is used widely as the modular basis of applications, enabling incorporation of a large set of libraries created by developers all over the world. A simple requirement for application extensibility is that that extensibility be based on the most widely accepted standard. That being the case, the ability for the NetBeans Platform to make use of OSGi bundles is not only an indication of its having adopted the generally accepted standard but also an indication of the versatility of the NetBeans Platform, since backward compatibility is holy to the NetBeans engineers.

So, how can OSGi be supported by the NetBeans Platform while not undermining backward compatibility? By enabling the NetBeans modular architecture to understand OSGi, in such a way that both/either can be used within desktop applications. Why not simply use Eclipse RCP instead if OSGi is what you want? Because Swing, on top of which the NetBeans Platform is based, is the other generally accepted standard, while not being native to Eclipse RCP.

Hence, there is the Netigso build of the NetBeans IDE:


It lets you combine NetBeans modules with OSGi bundles. (The name "Netigso" consists of "Net" from NetBeans, attached to "OSGi" spelled backwards.) For quite some time, that build has been broken. No more. It works now.

  1. Download the build above and then use it to create a new NetBeans module. In the manifest, change the "OpenIDE-Module" key to "Bundle-SymbolicName". Now, when you build the module, you will have an OSGi bundle because the NetBeans build system will create an OSGi bundle when the above key is set in the manifest.

  2. Let's now use some of the NetBeans API classes inside our OSGi bundle! Use the New Action wizard and then fill out the generated class like this:
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import org.openide.DialogDisplayer;
    import org.openide.NotifyDescriptor;

    public final class SomeAction implements ActionListener {

    public void actionPerformed(ActionEvent e) {
    NotifyDescriptor dd = new NotifyDescriptor.Message("Hello from " + getClass().getClassLoader());


    The New Action wizard registers the above automatically in the layer.xml file. (Isn't it cool that you can use a standard ActionListener to define your actions, rather than one that is specific to the NetBeans APIs?) Note also that the above implies that your module has a dependency on the NetBeans Dialogs API.

  3. Now run the module. A new NetBeans Platform application will start up and your OSGi bundle will be installed into it. That means that the NetBeans Platform's runtime container understands OSGi because it treats the OSGi bundle just like any other NetBeans module. Then, when you invoke the action provided by the OSGi bundle, causing the dialog to appear, you will see that OSGi is able to interact with the NetBeans Platform, since it needs to do so to be able to call into the NetBeans module that provides the Dialogs API.

Hurray. Now you're able to create complex desktop applications on top of OSGi and Swing, in a completely natural way, using NetBeans IDE. The result could be a robust and pluggable application, such as any of these. Meanwhile, backward compatibility is assured since NetBeans modules can be used exactly as before. 


Get the Java IDE that understands code & makes developing enjoyable. Level up your code with IntelliJ IDEA. Download the free trial.


Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}