e've come a long way from the days when the tools to which we most often turned to support us in developing applications were off-the-shelf commercial products. Today, thousands of developers have already adopted the open source frameworks Eclipse and NetBeans, and they haven't looked back.
One of the advantages of using Eclipse or NetBeans, of course, is that these frameworks are open to being extended however you like. Not surprisingly, there is great interest and excitement around doing just that. Companies and individuals alike are learning how to take their own tools and create plugins to one or both of the popular IDEs. The advantages of doing so include not just better productivity for your own team of Eclipse/NetBeans users, but a large, potential new audience of users and customers for your tool itself.
For the last year, I have been developing plugins for both frameworks, discovering the differences between NetBeans and Eclipse, and designing a code base that can be reused as much as possible. I've learned that there is no magic API that will work in both IDEs. However, there is a way to structure your code to minimize the amount of "re-write" necessary to achieve success in both IDEs.
Where appropriate, I have leveraged code from an existing tool I developed that plugs into both IDEs. These IDE plugins provide a visual UI design tool for building rich Internet applications (RIAs) in a drag-and-drop fashion.
Analyze Your Tool's Needs
|What You Need
| Eclipse version 3.0 and NetBeans version 3.6
A typical UI design tool will consist of one or more the following pieces of functionality that will need to be integrated into the IDE:
- ActionsMenu items and toolbar buttons that enable users to perform some kind of function.
- Wizards / Templates<Enable the user to quickly create objects needed for development, such as Java classes, SQL statements, and/or a wizard.
- Preferences / Options<Provide the user with the ability to store customization settings for their workspace.
- Views<Provide the user with a visual display for working with a specific piece of functionality.
- Editors<Provide functionality that increases the speed and accuracy of the code the developer is typing. Features such as auto-formatting and code completion are standards in today's editors.
Once you have decided what your tool needs to implement, you will need to architect your program to maximize code reuse. If you are integrating an existing tool into Eclipse and NetBeans, you will now have three applications to maintain. For this reason, it's critical that you reuse as much code as possible.
Eclipse vs. NetBeans
Once you have decided on the functionality that your plugin will need, it's time to integrate your tool into both IDEs, I'll walk through the steps to develop the plugins. I will not cover the basic steps of creating your plugin projects here because both IDEs have a set of wizards to guide you through that process. Instead, I will focus on differences in the code needed to get a tool to work in both IDEs.
The first thing I want to do is integrate an action (menu item) into both environments. This is a good example case for doing other types of integrations because the code needed to integrate an action is similar to most other types of functionality.
Step 1Define the action in the plugin's manifest file. Both Eclipse and NetBeans have the concept of a manifest file that describes the integration points of the plugin. Eclipse's manifest file is called plugin.xml. In NetBeans, you can specify the module's manifest file in the Manifest.mf file of your module's jar.
Implement the IDE's action interface that will be called when the user clicks on the menu item or toolbar button. In order for the IDE to interact with your plugin's functionality, you must implement an interface that the IDE knows about. This allows either NetBeans or Eclipse to invoke your object through reflection and then call method in classes. In the next section I show the interfaces you will need to implement to integrate an action into both IDEs.