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

Sudoku: OSGi-Based Web Development on the NetBeans Platform

04.20.2010
| 12856 views |
  • submit to reddit

Let's get started developing an OSGi-based web application on the NetBeans Platform. Today I explored the Sudoku Game by Peter Kriens in the context of a new NetBeans Platform application. In the end, I had the Sudoku Game up and running, after starting it from a NetBeans Platform application:

How to do this yourself? I.e., how to set up a web application that can use the NetBeans module system, as well as the Equinox container, at the same time? Read on.

  1. Download the latest distribution of NetBeans IDE 6.9. At the time of writing, it is under development, daily builds are available, milestones have been released, and the beta is around the corner.

  2. Create a new NetBeans Platform application atop Equinox, via this template:

  3. You can run the application that results from the above template, you'll see an application containing a window, displaying all the NetBeans modules and OSGi bundles that make up your application.

  4. Now download Equinox and download the two OSGi bundles that make up the Sudoku game. Put the following into the same folder somewhere on disk:

    • aQute.sudoku.jar
    • aQute.webrpc.jar
    • javax.servlet_xxx.jar
    • org.eclipse.equinox.ds_xxx.jar
    • org.eclipse.equinox.http_xxx.jar
    • org.eclipse.equinox.util_xxx.jar
    • org.eclipse.osgi.services_xxx.jar
    • org.eclipse.osgi_xxx.jar

  5. Right-click the application in the Projects window, choose Properties, go to the Libraries tab, click "Add Cluster" and then browse to the folder where the above JARs are found. Then a wizard opens that lets you convert the JARs to a 'cluster', i.e., a set of related modules/bundles that will be incorporated into your application:

    Set all imported OSGi bundles to "Enabled", so that they will be loaded and available at the time the application starts.

    When you click Finish, make sure that your "platform.properties" configuration file has content like this, otherwise manually tweak it:

    cluster.path.extra=netbinox:\../../path/to/my/nbsudokugame/folder
    disabled.modules.extra=org.netbeans.libs.felix
    cluster.path=\
    ${nbplatform.active.dir}/harness:\
    ${nbplatform.active.dir}/platform:\
    ${cluster.path.extra}
    disabled.modules=\
    org.jdesktop.layout,\
    org.netbeans.api.visual,\
    org.netbeans.core.execution,\
    org.netbeans.core.multiview,\
    org.netbeans.insane,\
    org.netbeans.libs.felix,\
    org.netbeans.libs.jsr223,\
    org.netbeans.modules.apisupport.harness,\
    org.netbeans.modules.apisupport.tc.cobertura,\
    org.netbeans.modules.autoupdate.services,\
    org.netbeans.modules.autoupdate.ui,\
    org.netbeans.modules.core.kit,\
    org.netbeans.modules.favorites,\
    org.netbeans.modules.jellytools.platform,\
    org.netbeans.modules.jemmy,\
    org.openide.compat,\
    org.openide.execution,\
    org.openide.options,\
    org.openide.util.enumerations
    nbplatform.active=default

    Note: The first line above points to the folder where I put the JARs referred to earlier.

  6. Then add this line to the "project.properties" configuration file of the application, which specifies that no splash screen will be shown (since you don't see a splash screen in a web application, do you?) and the port for deployment of the application:
    run.args.extra=--nosplash -J-Dorg.osgi.service.http.port=8080
  7. Run the application! All the OSGi bundles and NetBeans modules in your application will be deployed. The application for viewing the deployed OSGi bundles and NetBeans modules is deployed too, giving you a desktop application to monitor what is currently deployed, which is quite handy:

    Alternatively, delete the whole module that provides the window above. Then remove all the modules that are required by the above window, i.e., remove the window system, actions system, and everything else... except for the few JARs required by the OSGi integration: bootstrap, startup, filesystems, module system, utilities, and lookup.

    cluster.path.extra=netbinox:\../../path/to/my/nbsudokugame/folder
    disabled.modules.extra=org.netbeans.libs.felix
    cluster.path=\
        ${nbplatform.active.dir}/harness:\
        ${nbplatform.active.dir}/platform:\
        ${cluster.path.extra}
    disabled.modules=\
        org.jdesktop.layout,\
        org.netbeans.api.annotations.common,\
        org.netbeans.api.progress,\
        org.netbeans.api.visual,\
        org.netbeans.core,\
        org.netbeans.core.execution,\
        org.netbeans.core.io.ui,\
        org.netbeans.core.multiview,\
        org.netbeans.core.nativeaccess,\
        org.netbeans.core.output2,\
        org.netbeans.core.ui,\
        org.netbeans.core.windows,\
        org.netbeans.insane,\
        org.netbeans.libs.felix,\
        org.netbeans.libs.jna,\
        org.netbeans.libs.jsr223,\
        org.netbeans.libs.junit4,\
        org.netbeans.modules.apisupport.harness,\
        org.netbeans.modules.apisupport.tc.cobertura,\
        org.netbeans.modules.applemenu,\
        org.netbeans.modules.autoupdate.services,\
        org.netbeans.modules.autoupdate.ui,\
        org.netbeans.modules.core.kit,\
        org.netbeans.modules.editor.mimelookup,\
        org.netbeans.modules.editor.mimelookup.impl,\
        org.netbeans.modules.favorites,\
        org.netbeans.modules.javahelp,\
        org.netbeans.modules.jellytools.platform,\
        org.netbeans.modules.jemmy,\
        org.netbeans.modules.keyring,\
        org.netbeans.modules.masterfs,\
        org.netbeans.modules.nbjunit,\
        org.netbeans.modules.options.api,\
        org.netbeans.modules.options.keymap,\
        org.netbeans.modules.print,\
        org.netbeans.modules.progress.ui,\
        org.netbeans.modules.queries,\
        org.netbeans.modules.sendopts,\
        org.netbeans.modules.settings,\
        org.netbeans.modules.spi.actions,\
        org.netbeans.spi.quicksearch,\
        org.netbeans.swing.outline,\
        org.netbeans.swing.plaf,\
        org.netbeans.swing.tabcontrol,\
        org.openide.actions,\
        org.openide.awt,\
        org.openide.compat,\
        org.openide.dialogs,\
        org.openide.execution,\
        org.openide.explorer,\
        org.openide.io,\
        org.openide.loaders,\
        org.openide.nodes,\
        org.openide.options,\
        org.openide.text,\
        org.openide.util.enumerations,\
        org.openide.windows
    nbplatform.active=default

    Then you will have a non-GUI application, i.e., a server application, well suited for modular web development.

  8. Now put this URL in the browser (optionally, use URLDisplayer.getDefault() from the NetBeans UI Utilities API to open the browser at the required location programmatically) and the "index.html" defined within the Sudoku Game is deployed, displayed in the browser, and you can start playing the Suduko Game:
    http://localhost:8080/rpc/sudoku/index.html

Congrats, your first OSGi-based web application on the NetBeans Platform + the Equinox container that will be part of NetBeans IDE 6.9.

Further reading:


Also read New Cool Tools for OSGi Developers.

 

 

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

Comments

telman shahbazov replied on Fri, 2010/04/30 - 4:52pm

thanks for article.


os: ubuntu 9.10, netbeans6.9beta.

trying to add cluster : Cluster is not Valid.
I click the next button  and see all bundles have IGNORE status
I could not enable them. enabled option is not accessible.(no action on dropdown or right click menu)
Is there something I missed ?
 
Please advise.
Regards,
Telman

Comment viewing options

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