Plug-in Development 101: The Fundamentals
Join the DZone community and get the full member experience.Join For Free
plug-in development in eclipse is somewhat of an art form. if you're new to the concept of plug-ins, especially in the context of osgi and eclipse, it can be quite burdensome learning the myriad tools eclipse has to help you write plug-ins. the purpose of this article is to help you learn some basic plug-in development skills with some best practices sprinkled in for good measure.
this series of articles is all about developing plug-ins. but before we get started, we need to ensure that we have a proper environment in which to develop plug-ins. the first step is to download an eclipse distribution that has the plug-in development environment (pde) in it from eclipse.org. i recommend downloading the latest version of eclipse classic. in this series, we will use a milestone release of eclipse v3.4 (m5). once this done, you're ready to go.
to make it easier to understand plug-in development, this article will follow a workflow detailed in figure 1. in part 1 of this series, we will focus on the first five steps of the workflow. we will leave the last two steps for part 2, which will focus on rich-client applications.
[img_assist|nid=2738|title=figure 1: plug-in development workflow|desc=|link=none|align=undefined|width=500|height=290]
before we dive into the details of plug-in creation, let's discuss what a plug-in exactly is. technically, a plug-in is a java™ archive (jar) that is self-contained and self-describing. it's self-containing because it houses the code and resources the plug-in needs to run. it's self-describing because it includes information stating what it is, what it requires from the world, and what it contributes to the world. in a plug-in, you will generally see two descriptor files: a manifest.mf and plugin.xml.
the first part of the plug-in development workflow involves creating a plug-in project. in eclipse, this is easily done by selecting the new >project... menu option. in the wizard presented, select plug-in project as the type of project you want to create.
[img_assist|nid=2739|title=figure 2: new plug-in project wizard|desc=|link=none|align=undefined|width=500|height=574]
just like any other eclipse project, the wizard asks you to choose a project name. i suggest
. there is also an option to choose a target platform. a target platform in this context simply means whether you will target a version of eclipse or an osgi framework like equinox. in this case, we'll target the 3.3 version of eclipse to keep things straightforward. the next page of the new plug-in project wizard focuses on plug-in content.
[img_assist|nid=2740|title=figure 3: plug-in content|desc=|link=none|align=undefined|width=500|height=574]
on the plug-in content wizard page, we must complete a form to make our plug-in compliant with eclipse. the plug-in identifier is a field that represents a unique identifier for your plug-in. no other plug-in can share the same identifier. the plug-in version is composed of four segments (thee integers and a string) respectively named major.minor.service.qualifier (see resources for the eclipse plug-in versioning guide). the plug-in name simply represents a human-readable name. the plug-in provider field is a human-readable string signifying the author of the plug-in. in simple terms, the execution environment (ee) field represents what minimum jre your bundle is capable of running on (see resources ).
the wizard gives us an option to generate a plug-in activator. a plug-in activator is simply a class that controls the life cycle of your plug-in (think of it as a start-and-stop method). customarily, the activator is responsible for setting up things and properly disposing of resources when your plug-in isn't needed anymore. in this case, we desire an activator, a plug-in that makes contributions to the ui, and we're creating a rich client platform (rcp) application (see resources ).
the final step in plug-in creation involves selecting a template (see figure 4) to base your new plug-in on. when you get more advanced in the creation of plug-ins, this step is usually skipped. however, beginners need to start somewhere, and the eclipse sdk ships many templates to help you get started. in this case, we select the basic hello world with a view application.
[img_assist|nid=2741|title=figure 4: plug-in templates|desc=|link=none|align=undefined|width=500|height=574]
after completing the previous step, a new plug-in was created in the workspace. we're now presented with an editor (see figure 5) to help us work with the fresh plug-in. the first page in the editor we see is the overview page, which contains modifiable plug-in identifier information with sections describing the various items you can edit within our plug-in. for example, we see the identifier (id) and version fields we previously defined using the template shown in figure 4.
[img_assist|nid=2742|title=figure 5: plug-in editor (overview page)|desc=|link=none|align=undefined|width=572|height=469]
extensions and extension points
the next step on our plug-in adventure involves adding an extension. however, before we dive into the details, let's first understand two important topics when developing extensible eclipse plug-ins: extensions and extension points. using a simple analogy, you can think of an
as a plug and an
as a socket. each extension point is unique and defines a contract to be adhered to. for example, eclipse ships with an
extension point (socket) that allows you to supply our own editor (the plug).
in our case, we'll create a new extension that contributes to the eclipse toolbar. to accomplish this, we will use a template (similar in concept to the template we used to create our plug-in) for the
extension point. from the overview page in the plug-in editor, select the
link in the
extension/extension point content
and select the
template (see figure 6) with all the defaults filled in.
[img_assist|nid=2743|title=figure 6: extension templates|desc=|link=none|align=undefined|width=414|height=587]
an important part of our plug-in is that it's self-describing. one of the things our plug-in must describe is what it offers the world. in the context of eclipse, these are called exported packages . in our plug-in, we get to decide what packages we export so other plug-ins can peek inside those packages to see they depend on our plug-in. it's also possible to mark exported packages as being internal, which tells plug-in developers that we don't consider the package in question as api. to specify exported packages, we use the runtime page within the manifest editor.
[img_assist|nid=2744|title=figure 7: runtime page|desc=|link=none|align=undefined|width=558|height=480]
in the previous section, we described what a plug-in must do to expose its functionality to the world. imagine you are a different plug-in and wanted to use the aforementioned functionality. how would you express your interest in doing so? in the context of eclipse, these are called
. in the simplest case, plug-ins can depend on other plug-ins. for example, if you want to build your own editor in eclipse, you would need to depend on the
plug-in. to specify dependencies, you have to be on the
page of the plug-in editor.
[img_assist|nid=2745|title=figure 8: dependencies page|desc=|link=none|align=undefined|width=561|height=479]
note that on top of depending on individual plug-ins, you can choose to depend on packages that are exported from plug-ins (see the imported packages section on the dependencies page). this is more of an advanced topic and useful when you don't want to tie your plug-in to a specific implementation. for example, imagine depending on a package
that supplied an xml parser. now picture having two plug-ins like
that provided two different implementations of the same xml parser, but for different environments.
the runtime and dependencies pages are just visual representations of what is specified mainly in manifest.mf file. for advanced users wishing to edit the source of this file by hand, pde offers a source editor with code completion for the various headers found in a plug-in manifest definition.
[img_assist|nid=2746|title=figure 9: source editing|desc=|link=none|align=undefined|width=558|height=477]
testing and debugging
the next step on our plug-in adventure involves testing and debugging. to test our plug-in, eclipse and pde have a notion of self-hosting. self-hosting simply means that we're able to launch a new eclipse with plug-ins we're currently working on in our workspace without actually having to export or deploy any plug-ins. to launch a new eclipse, all you need to do is start another runtime workbench via the overview page's testing section (see the launch an eclipse application link within the overview page). after a few seconds, you'll notice a new workbench pop-up with your plug-in's sample action visible in the toolbar.
[img_assist|nid=2747|title=figure 10: self-hosting in eclipse|desc=|link=none|align=undefined|width=234|height=175]
to launch your self-hosted plug-in in debug mode, simply click the launch an eclipse application in debug mode link in the testing section of the overview page. to actually debug your plug-in, you need to set relevant breakpoints. if you're new to debugging in eclipse, i recommend checking out the developerworks article "debugging with the eclipse platform" to help get you started (see resources ).
to set more fine-grained options about launching or debugging your plug-in, go to the launch configurations dialog, which can be invoked using the run > run configurations... menu option. the relevant launch configuration type for your plug-in is called an "eclipse application" since what we're launching is indeed an eclipse application (see figure 11). within the launch configuration, you can set things like arguments and have control over which jre is used to launch your application.
[img_assist|nid=2748|title=figure 11: launch configurations dialog|desc=|link=none|align=undefined|width=572|height=385]
a common step in plug-in development is internationalization. once you get to a point where your plug-in is useful and will be tested by multiple parties, you often get a request to make sure your plug-in is capable of running in a different language. thankfully, the amount of work needed to externalize plug-in related strings is minimal. in pde, there is a wizard that can be invoked via right-clicking on the overview page of your plug-in and selecting the externalize strings... menu item. after the selection, a wizard will be presented that displays all the strings that are relevant to externalization.
[img_assist|nid=2749|title=figure 12: the externalize strings wizard|desc=|link=none|align=undefined|width=563|height=484]
in reality, this simply generates a plugin.properties file (that contains externalized strings) for your plug-in and adds the
header to your manifest.mf file. the
header simply lets you define a name and optional location for your externalized strings. in this case, the
is "plugin," which signifies that strings for various locales will be in files like plugin.properties (see figure 13) plugin_fr.properties or plugin_de.properties. anything after the underscore in the file name represents the locale.
[img_assist|nid=2750|title=figure 13: the plugin.properties file|desc=|link=none|align=undefined|width=366|height=195]
that's it! that's all that's involved to get started in internationalizing our plug-in. for more information, i recommend reading these outdated yet still relevant articles from the eclipse corner: "how to internationalize your eclipse plug-in" and "how to test your internationalized eclipse plug-in" (see resources ).
the next step on our journey is to organize our manifest files (i.e., manifest.mf and plugin.xml) with some best practices. pde provides a convenient wizard that can be invoked via the overview page's exporting section. once the wizard is launched (see figure 14), you're presented with a variety of options that can be tweaked. the defaults are very reasonable, but there are certain options like making sure there are no stray keys in the plugin.properties file, which is very useful.
[img_assist|nid=2751|title=figure 14: the organize manifests wizard|desc=|link=none|align=undefined|width=572|height=558]
on the whole, this article's mission was to give an introduction to the basics of plug-in development with some best practices sprinkled in. we accomplished that by creating a sample plug-in and going through a typical plug-in development workflow. once the workflow is learned, it becomes much easier to develop plug-ins and even easier to maintain them with best practices like the organize manifests wizard. part 2 will focus on using the tooling available for developing rich-client applications and finishing the rest of the plug-in development workflow presented in figure 1.
learn more about
learn more about
eclipse plug-in versioning
at the eclipse foundation wiki.
eclipse ee guide
at the eclipse foundation wiki.
learn more about the
eclipse rich client platform
to learn more about the eclipse sdk, see the eclipse foundation documentation titled "
platform extension points
need help debugging in eclipse? read "
debugging with the eclipse platform
good background information on internationalizing plug-ins can be found in the eclipse foundation's articles "
how to internationalize your eclipse plug-in
" and "
how to test your internationalized eclipse plug-in
check out the "
recommended eclipse reading list
browse all the
new to eclipse? read the developerworks article "
get started with eclipse platform
" to learn its origin and architecture, and how to extend eclipse with plug-ins.
expand your eclipse skills by checking out ibm developerworks'
eclipse project resources
get products and technologies
eclipse distribution containing the plug-in development environment (pde)
the first stop to make when seeking plug-ins is the
eclipse foundation's project list
the second stop to make when seeking plug-ins is
eclipse plug-in central (epic)
check out the latest
eclipse technology downloads
eclipse platform and other projects
from the eclipse foundation.
eclipse platform newsgroups
should be your first stop to discuss questions regarding eclipse. (selecting this will launch your default usenet news reader application and open eclipse.platform.)
has many resources for people interested in using and extending eclipse.
and get involved in the developerworks community.
chris aniszczyk is an eclipse committer at ibm lotus who works on osgi-related development. his primary focus these days is improving eclipse's plug-in development environment (pde) and spreading the eclipse love inside of ibm's lotus organization. he is an open source enthusiast at heart, specializing in open source evangelism. he evangelizes about eclipse in his blog, and he's honored to represent the eclipse committers on the eclipse foundation's board of directors. he's always available to discuss open source and eclipse over a frosty beverage.
Opinions expressed by DZone contributors are their own.