NetBeans IDE 4.1: Great Test Environment for Modules

Developing a NetBeans Module (NBM) can be a surprisingly smooth process. For example, the illustration below shows the state of my TagExtension module yesterday. At the top of the Projects window you see the module project (which is actually just a plain old J2SE project). Beneath it is a random web application project that I'm using to test the module. In the illustration, you see a tag called abc.tag with an icon and menu items provided by the TagExtension module (click to enlarge):

Now lets say I want to add some more menu items. This means modifying the TagExtensionNode class. So let's add a whole bunch of new menu items, all defaults provided by the system -- none provided by ourselves yet. So we change the code to look as shown in the illustration below (interestingly, a line consisting of null, represents a separator in the list).

After we've rebuilt the NBM using the same Ant scripts as before, we simply go to the Options window, find the module, delete it, after which we go to the Update Center, browse for the updated NBM, and install it. Right? Wrong. That's just far too much work. Instead, get yourself an org-netbeans-modules-apisupport-ant.jar. (If you don't have it locally, go to the Update Center and install the Open Ant API Extensions. Make sure you install them globally, otherwise you might not find the JAR, especially if you're a Linux user. When you install a module globally -- it's an option somewhere in the Update Center process -- it ends up in the nb41 folder of your NetBeans IDE installation directory instead of in your user directory.) Once you have the org-netbeans-modules-apisupport-ant.jar attached to the module project (right-click the Libraries node and browse to the JAR), add the following to your build.xml file:

<target name="reload" description="Reload NBM File.">
  <nbinstaller module="${dist.jar}" action="reinstall"/>

And then, this is where the magic really comes together: add the reload target to the -post-jar target:

<target name="-post-jar" depends="create-xml-file-for-module,create-nbm,reload" />

Now this is all really cool -- and really only because the -post-jar target is really cool. It is called whenever the jar target is called. And guess where the jar target is? It is hooked up to the project's Build Project menu item. So, whenever you right-click the TagExtensions module and choose Build Project, the NBM is rebuilt and reloaded into the IDE. This means that you can see the results immediately. Great for testing your module, right? After I added a whole bunch of new menu items to the TagExtensions module, I just right-clicked the project, chose Build Project, waited 2 seconds for the whole process to unfold, and then right-clicked my abc.tag again. And this is what I saw (click to enlarge):

Not bad, huh? As far as I'm concerned, the IDE together with Ant is a fantastic NBM development environment. Sure, there are a few things to figure out, but isn't that fun? I feel really good whenever I discover some new way to hook things up to the IDE. I'd hate to have someone do everything for me. As a developer, it's really cool to be creating applications while simultaneously looking for ways to improve the IDE that I'm using and then being empowered to do it by the very same IDE. Cool stuff.


Post a Comment:
  • HTML Syntax: NOT allowed

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« February 2015