Free tutorials for Java, Eclipse and Web programming



Eclipse Extension Points and Extensions - Tutorial

Lars Vogel

Version 1.0

20.04.2009

Revision History
Revision 0.1 - 0.718.09.2008Lars Vogel
Created article
Revision 0.805.04.2009Lars Vogel
Added explanation Extension point vrs. Extension
Revision 0.919.04.2009Lars Vogel
Improved overview part
Revision 1.020.04.2009Lars Vogel
Introducted ISafeRunnable

Eclipse Extension Points

This article will describe the definition and usage of the Eclipse Extension Point mechanism. The examples used will be based on Eclipse RCP therefore basic knowledge of Eclipse plugin or Eclipse RCP development is assumed.

In this example Eclipse 3.4 and Java 1.6 are used.


Table of Contents

1. Extensions and Extension Points
1.1. Overview
1.2. Definition
2. Hello World extension point
2.1. Creating the extension provider
2.2. Evaluating the registered extensions
2.3. Providing an extension
2.4. Run the example
3. Thank you
4. Questions and Discussion
5. Links and Literature
5.1. Source Code
5.2. Other Resources

1. Extensions and Extension Points

1.1. Overview

Extension Points allow that functionality is contributed to a specific plugin which defines this extension point. The functionality can then be contributed by any plugin which defines an extension for the defined extension point.

So an overview:

  • Extension Point: Defines the possibility to add functionality

  • Extension: Uses the extension point to provide functionality, also known as contributions

Functionality can be code but also non-code related contributions, e.g. help context.

The plugin which defines extension points defines a contract for other plugins how these plugins could provide functionality via this extension point.

The plugin which defines the extension point is also responsible for evaluating the contributions.

1.2. Definition

To define a extension point you perform the following:

  • Design the extension point

  • Define the extension point in the MANIFEST.MF

  • Write code to load the extensions to this extension point

  • Load / Call the extensions when needed

Extension points are defined via the file plugin.xml. For example the following show the extension point which will defined in the following example.

				
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<plugin>
   <extension-point id="de.vogella.extensionpoint.greeters" name="Greeters" schema="schema/de.vogella.extensionpoint.greeters.exsd"/>

   <extension
         id="application"
         point="org.eclipse.core.runtime.applications">
      <application>
         <run
               class="de.vogella.extensionprovider.simple.Application">
         </run>
      </application>
   </extension>

</plugin>
			

The extension point refers to an XML Schema which defines the details of the extension point.

Eclipse provides for both files a powerful editor which the following example will demonstrate.