Eclipse Plugin Development

Eclipse isn’t a huge single java program, but rather a small program which provides the functionality of typical loader called plug-in loader. Eclipse (plug-in loader) is surrounded by hundreds and thousands of plug-ins. Plug-in is nothing but another java program which extends the functionality of Eclipse in some way. Each eclipse plug-in can either consume services provided by other plug-in or can extend its functionality to be consumed by other plug-ins. These plug-in are dynamically loaded by eclipse at run time on demand basis.

Creating a Plug-in
1. Launch Eclipse.
2. From File menu, select New Project. This will open up New Project wizard.
3. Now select Plug-in Project and click on the next button.

 

4. On next page of the wizard , enter the name of the project "com.myplugin.rmp"

5. Fill in the other fields as shown and then click the Next button. The next wizard page displays options for generating plug-in Java class. Fill all the fields as shown below. Do not fill anything in classpath field – This has been removed in eclipse 3.4. Plug-in Activator is required if we want to do anything on plug-in start up or shut down. For example we want to acquire some resources at plug-in start up and perform clean up when plug-in is shutdown. It is important to note that Eclipse startup does not essentially means that your plug-in is starting up. Plug-ins are loaded/started only when they are demanded or required. So activator is used when plug-in startup/shutdown happens.

 

6. Click Next, select Plug-in with a view and then click the Next button.

7. Next, Enter the values for this page, and click the Next button.

 

8. Finally, uncheck all the options. and click Finish button.

After completing New plug-in Project wizard following directory structure will be created.

 

Four important files to look for are:

    RmpPlugin.java – This is the main plug-in class. When plug-in is activated, startup method of this class is called. This class can be used to initialize plugin specific resources. ResourceManagerView.java – This is the View class which gets generated. This class contributes to the UI of our example Resource manager plug-in. MANIFEST.MF – defines runtime information of the plugin Plugin.xml – defines the extension information of the plug-in. </LI>

Manifest Editor – Dependencies Tab

In This section a plug-in must list all the dependent plug-ins which are required so that our plug-in compiles. As you know that we build our plug-ins on top of other plug-ins, so this section essentially declares all those dependencies.
It must be noted that all above plug-in dependencies must be met before plug-in is resolved. It is always good to scan your dependencies from time to time and remove unused dependencies. In order to know unused dependencies use Dependency Analysis section.

Manifest Editor – Runtime Tab

On this page plug-in declares what all it exposes to the outside world. Lets understand this concept with an example. Say you are building Plug-in A. Now if plug-in B wants to extend plug-in A or wants to use plug-in A in any way it will be required that Plug-in A exposes its API’s. It is here that Plug-in A would declare all the packages which it wants to expose to outside world. You can use Add.. button to see all your plug-in packages and then select all Packages which you would like to export.
Another important section on this page is the Classpath. If your plug-in is using some external jars then it is important to add such jars to runtime classpath. Note that simply adding such jars to project classpath will only help you in compiling your source code. In order to make these jars available to runtime environment use Classpath section.

Manifest Editor – Extensions Page

 

Extensions page is a viewer on top of plugin.xml. This is one of the most frequently used page in plug-in development. This page makes it easy to create extensions as this page is aware of all the extension points. Eclipse provides around 213 extension points where clients can contribute functionality. Extension points are available for virtually every thing for ex: builders, editors, preferences, help contents, markers, views, perspective and so on. Basically we select some extension point and then use these to build our own extensions.

Manifest Editor – Extension Points

This page is also a viewer on top of plugin.xml. This page is used to define our own extension points. Such extension points define a contract which other plug-ins may agree to abide by and extend plug-ins functionality in some way.

Test New Plug-in

There are two ways to test this plug-in. First, we can build a product which will essentially create a plugin bundle, this bundle is then dumped into plug-in folder of eclipse installation. Second, launching new plug-in from within Overview tab of manifest editor. At this time we will take second approach to test this plug-in. This is also the preferable choice when we are developing eclipse plug-ins and need to test them from time to time. In order to test this plug-in click on Overview tab followed by clicking on link Launch an Eclipse Application.

 

This will launch another instance of eclipse application. However, this new instance will have our plug-in registered with it, So we will be able to see resource manager view. After New Eclipse has started, from the Window menu, select Show View > Other… to open the Show View dialog . In the dialog, expand the Resource Manager Category, select Resource Manager View, and then click the OK button. This causes the Resource Manager view to open.

Leave a Reply