Geertjan's Blog

  • April 25, 2009

Sharing Code Between Different NetBeans Platform Applications

Geertjan Wielenga
Product Manager
One of the cool things about the various interviews with NetBeans Platform developers, mostly published on NetBeans Zone (the latest one here about a commercial application for oil & gas exploration, published today), is that you get to see the real life issues that developers are struggling with. In the story Collision Repair Shops on the NetBeans Platform, the first item in the list under the question "What are some areas where the NetBeans Platform can improve?" is as follows:

I would really like to be able to easily reuse modules in other Suites. It is sort of possible now, but it is difficult. We used to do suite chaining - but refactoring was too painful so we are back in a single suite.

Well, as everyone on the NetBeans Platform mailing list should know by now, the upcoming 6.7 release of the NetBeans Platform will completely solve this problem. In fact, as a result, there will no longer be a boundary between one application and the next, which is of particular usefulness when several applications are being developed on the NetBeans Platform by one single company.

Here is a very practical example. Imagine you're developing music applications. Below, I have simulated this scenario, by means of two applications, one for harmonica players and one for guitar players. (Of course, that's a bad decision to begin with since everything should be integrated into the JFugue Music Application Platform, the only reason why this isn't possible yet is because I haven't got around to restructuring it to allow that to be possible.)

So, anyway, here are the two applications.

Let's assume we started out creating an application for harmonica players, so we created an API in the typical NetBeans Platform fashion, i.e., in a separate module. Now, later on, we find out that we also have guitar players, so we create a separate application for them (no harm in that, just like PHP developers are happy with a PHP-only version of NetBeans IDE, maybe guitar players would like a separate application that doesn't have harmonica features). We could, of course, use the same application as before, but remove the modules that guitar players don't need, and so on. However, now that it's possible to share modules between applications, it's also possible to structure applications on a higher level... i.e., not focusing on modules as the largest structure, but applications as the ultimate container, i.e., two steps above package level.

And this is how. In my guitar application, I go to the Project Properties dialog, specifically to the Libraries panel. This is what I see there by default:

Now I click the brand new "Add Project" at the bottom of the above dialog and then I can browse to the harmonica application which, when I click OK, is then added to the dialog as a new cluster:

By default, all modules from my harmonica application are selected. But in this case I only want to use the API, so I only select that one. (Maybe it would be nice if I could specify, per module, whether the module should be shareable with other applications? Because, in this case, I'd prefer to disable the UI module from being exposed to other applications. Or maybe that's possible and I haven't seen that setting.)

And now, in my guitar application, I can set a dependency on the API module (which is an API module because at least one of its packages has been exposed to the outside world via the "API Versioning" panel of its Project Properties dialog), so that I can now implement the API defined in the other module:

And the API module from the other application will be treated like any other module in any of the clusters that are enabled in the guitar application, i.e., it will be included when I build the application and will be part of the ZIP file when I build the ZIP archive.

Note especially that everything done here has been done via the UI, i.e., nothing at all needs to be tweaked in configuration files and so on. That's pretty cool. I'm looking forward to seeing the various benefits that NetBeans Platform developers will be able to gain from this feature. At the very least, I believe that the collision repair shops in Sydney should find this a nice improvement. :-)

Join the discussion

Comments ( 6 )
  • Mark Saturday, April 25, 2009

    You have to become one with your application. Blurring the lines, and eliminating the separation between programmer and application. Be your program. The API(Application-Programmer Interface). :)

    musiccapi, eh?

    package blahblahblah

    import dmtmusic.org.demo.Note


    else lprint "Sorry";


  • Damian Carey Sunday, April 26, 2009

    Wow! Thanks for the personal service! Clearly it will not be just us at Quotimation benefiting from this change to the Netbeans Platform.

    The specific benefit to us is in establishing our "common" project that contains our core competencies (distributed rich UI). This is immediately worthwhile even just for modularity and good software engineering practice, but the real value from this will arrive in 2 to 5 years as we leverage our existing product into new products.

    For decades the software profession has being trying to leverage existing effort through software reuse, everything from simple "copy and paste code", to sharing libraries/jars, even frameworks. This next stage of the Netbeans Platform gives us (as a small evolving software shop) the ability to move way beyond all that, indeed it enables us to seamlessly and easily leverage our own code by reusing whole projects.

  • Geertjan Thursday, April 30, 2009

    We aim to please, Damian!

  • MiKom Tuesday, July 21, 2009

    Is there any way to make NetBeans build child module suites when parent suite is built?

  • Aaron Monday, September 21, 2009

    We have tried this with our apps, but with the following problem: The Tools->Plugins menu item is missing from the "new" application (Guitar in your example) that suite chains in the first application (Harmonica in your example). The menu item does exist in the original application (Harmonica). Did we miss something?

  • Geertjan Wielenga Monday, September 21, 2009

    The Tools|Plugins menu item is provided by two AutoUpdate modules in the platform cluser. Sounds like you didn't check those boxes in the Libraries panel. Drop me an e-mail at geertjan dot wielenga at sun dot com if you continue being stuck on this one.

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.