Sharing Code Between Different NetBeans Platform Applications
By Geertjan on Apr 25, 2009
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. :-)