Extend an Existing NetBeans IDE Project's Functionality

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.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

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.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
24
25
26
27
28
29
30
   
       
Today