X

Geertjan's Blog

  • July 29, 2005

Extend an Existing NetBeans IDE Project's Functionality

Geertjan Wielenga
Product Manager
I found out yesterday how easy it is to create a plug-in that adds a new project-level menu item. It means making a very simple addition to the layer.xml file. I imagine that the new Delete Project menu item (available now from the Update Center) was probably added in this way. Here's what you do:

<folder name="Projects">
<folder name="Actions">
<file name="org-myorg-genericprojectaction-GenericProjectAction.instance" />
</folder>
</folder>

And then you can invoke the action from a project's contextual menu:

To put the action in a different place in the contextual menu, you'd use the <attr> element, but then you'd need to know the real name (i.e., not the name that appears on the menu item but the name that you'd find in the localization bundle). And that's always a problem to work out -- a lot of digging through the NetBeans sources to see what something else is called, in order to know where the thing you're actually interested in should go.

In addition, I can imagine some actions that are relevant to web projects, but not to J2SE projects. Or J2EE-related project actions that have no relevance for web projects. However, I don't think it's possible (yet) to make that distinction in the layer.xml file.

By the way, using the layer.xml file like this is similar to what you do in free-form projects (i.e., not the standard projects for which the IDE generates its own Ant file) with Ant targets -- you can hook Ant targets up to a free-form project's contextual menu, but then only to a specific project, not to all projects simultaneously. On top of that, of course, the functionality that a plug-in offers is, at least potentially, much more extensive than what an Ant script can provide. And -- most important of all -- you can share a plug-in much more easily than an Ant script. Just put the NBM file in an e-mail, for example, or make it available via the Update Center. The Ant script, no matter how useful it is, requires a lot of little fiddly steps before it's hooked into someone else's project.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha