Now that I can create a NetBeans Module -- albeit a very simple one -- I'd like to be able to transform an existing J2SE application
into a NetBeans Module. What would I have to do to make this possible? Here's a short list:
- Specify the changes that you want to make to the filesystem. Do you want to access the module from a menu item? A toolbar button? Or some other way? Create a layer.xml file for this purpose.
- Create an Action class that extends CallableSystemAction. What's very important is the performAction method, which provides the entry point to the module.
- Make sure that the IDE interprets the application as a module. To do this, add module entries to the manifest.mf file.
- Modify the application so that it works as a module. Many things to be considered here -- the more complex the application, the more intricate the considerations. Sandip Chitale has given me the following tips:
- You should not set the "defaultCloseOperation" property of a Frame to "EXIT_ON_CLOSE". Although this works for simple applications with one frame, you do not want the whole NetBeans JVM to exit when the user closes the Frame. Therefore, change the property to "DISPOSE_ON_CLOSE" instead.
- You should not hook the low level event MouseClicked to perform an action. Instead, you should hook the abstract event ActionPerformed. That is because you want your code to be invoked not only when the user does a mouse click but also when the user presses the spacebar or return key from the keyboard. (This comment not necessarily related to modules specifically, but useful comment nonetheless!)
- Generate the XML file that describes the module, as well as some related files (for update tracking purposes). Use the cluster harness or your own Ant script for this. Refer to the previous blog entry for details on the Ant script as well as on the properties that need to be set if you use a non-standard nbantext.jar file.
- Finally, generate the NBM itself. The method is the same as above -- use the cluster harness or your own Ant script. Refer to the previous blog entry for details on the Ant script as well as on the properties that need to be set if you use a non-standard nbantext.jar file.