Friday, August 29, 2008

Netbeans6.1 Plugin - Export as archive

Netbeans has been a fascination for me. Ere it was Forte For Java which was then rechristened as sun java studio. Those were the days. Then Netbeans 5.0 happened. It was time to bid adieu to Java studio. In my current place of work, I am the source of frustration and amusement to many people since I am the only one to use Netbeans when the rest of the organisation is eclipse based. So you can see that friction is high because I am one against many in a debate on which is better - Netbeans or Eclipse. (see my previous post on why I find Netbeans as a better option). In one such debate came the notion of export as. Eclipse has many options for their Export As feature. But Netbeans does not. And so this plugin.

You can download the plugin from the netbeans plugin portal Export as archive. It is not available in the Plugin-manager now pending verification.

Supported Platform - Netbeans 6.1
You can click the Download button on the banner to the left to get Netbeans.

Plugin details -
The source code is available at

Now for the interesting parts.
The action extends from CookieAction and Over-rides two methods of interest
  • performAction(Node[] activatedNodes)
  • enable(Node[] activatedNodes).
first the enable method
This ensures if for a selected node the export option should be enabled or not. I would have preferred along with that a visible option. But since that is not available will survive with it though. So the way I am enabling the option is checking with the DataObject. If the DataObject does not have a primary file, then don't enable other wise enable it.

performAction method - delegates call to a simple private method.
This method picks up the primary file from the DataObject, constructs an Ant Script. The idea of using an Ant Script was inspired by Geertjan's blog. Earlier I used a grossly inefficient way - traversing directories and adding them to a Zip stream.

Steps to create such a Plugin
1. Create a New Project - Choose Netbeans Module-->Module
2. In the next screen fill up the entries but ensure that the Standalone radio button is selected.Tis marked in a red box.
3. Finish the wizard.
4. Click on the Project and Select New (Bring up the New File wizard)
5. Select Conditionally Enabled radio button and DataObject from the dropdown/combo box
6. In the next screen you can choose any combinations
7. Complete the wizard steps.
8. Provide implementation for the performAction method.
Simple 8 steps.
What to expect in future? For now I am thinking of two things. You can pour in your views.
1. Multiple Selected nodes (With restrictions of course)
2. Wizard like facility to choose destinations.

Enjoy archiving your projects.


Don said...

I am a high school CS teacher. Your plugin works very well for Netbeans 6.7 and has made zipping projects very easy for my students.

However, it doesn't seem to be available for v6.9? Any plans to make it available?


Karl said...

When looking at the plug-in manager, check your settings for which update centers are included. I was able to get the plug-in for 6.10 M1, so it is there somewhere - probably you need to include the Plugin Portal Update Center.