Eclipse plugin development with Maven.


Setting up new Eclipse project for plugin development is very ease if you use maven. I have created simple project that you can use as an example with you development.
You don’t really need to install any plugins like JDT (Eclipse Java Development Tools), for your eclipse, or install specific version of eclipse with integrated JDT.
When you import maven project from specific pom, needed plugins will automatically install into your eclipse. On the other hand if you do not want to use eclipse as your IDE while development you can just compile it form command line with maven commands. More on that later.
To summarize you need maven installed in your system, if you want to develop using eclipse, you just need version for java development, with m2e plugin (Maven support in eclipse).

What will we have

Clicking on Java project to see context menu, then on item „Show Class Graph”…
shows dialog window with project path as message:

Starting up


For full review you can just clone git project from the folowing location Checkout to tag v0.0.1 where you have the first relevant commit with working plugin.

Eclipse Import

You can import this project into eclipse by going:
(from context menu on Package Explorer) Import->Maven->Existing Maven Projects
Then select location of cloned project’s pom file.

Maven Building

You can also build it using maven by:
mvn clean package
This command will build plugin in your target folder, plugin in this case will have name: ‚com.morcinek.uml.class-graph-plugin-eclipse-0.0.1.jar’, where ‚com.morcinek.uml.class-graph-plugin-eclipse’ – artifact name from pom file, ‚0.0.1’ version from pom file.

Maven Project

As you can see this maven project has one module which is responsible for plugin development. Making modules in such small projects doesn’t make sense, but it will in the future when you want to add reference projects or extra libraries.
So lets start with root pom.

<project xmlns="" xmlns:xsi=""
	<name>Uml parent project</name>


Important are declaration of eclipse repositories from where maven downloads plugins and dependencies while building.

The plugin pom file.


In this file packaging is important, it says to maven that we want to build eclipse plugin. In build section plugin declarations are used while building, thanks to them project is build correctly. Packaging and plugin declarations are required for maven to build eclipse plugin.

Build properties

Another important file is, which looks like this:

source.. = src/main/java,\
output.. = target/
bin.includes = plugin.xml,\

This simple example as you can see describes where is the source code, output, and which files you also want do include in plugin without building (bin.includes). In further development when you want to add reference project or libraries this file will be relevant.

Plugin configuration

More complicated is plugin.xml file:

    <extension point="org.eclipse.ui.menus">
        <menuContribution locationURI="popup:org.eclipse.jdt.ui.PackageExplorer">
            <command commandId="com.morcinek.uml.class_graph.plugin.convert"
                     label="Show Class Graph"
                        <count value="1"/>
                                <adapt type="org.eclipse.core.resources.IProject">
                                    <test property="org.eclipse.core.resources.projectNature"

    <extension point="org.eclipse.ui.commands">
        <command defaultHandler="com.morcinek.uml.class_graph.plugin.Convert"

This is the description on where and when should the option be visible, and how it should be handled.
From file you can find out that option appears in contect menu while clicking on the Java Project element in PackageExplorer. Clicking on the option with name Show Class Graph will be handled by class:

Manifest File

There is an MANIFEST.MF file located in folder META-INF/. I have used following file:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Class Graph Display
Bundle-SymbolicName: com.morcinek.uml.class-graph-plugin-eclipse;singleton:=true
Bundle-Version: 0.0.1
Bundle-Vendor: MORCINEK
Require-Bundle: org.eclipse.ui,
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Eclipse-LazyStart: true
Export-Package: com.morcinek.uml.class_graph.plugin
Bundle-ClassPath: .

As you can see file contains important data about plugin. The most important and relevant on this stage are:

  • ‚Bundle-SymbolicName’ – needs to be the same as artifact name in pom file.
  • ‚Require-Bundle’,’Import-Package’ – I am not sure about that, and I am to lazy to check, those names give a clue of that those packages are responsible for. Thing is that if you want to use jdt classes from those packages you need to declare them in one of those sections. (you can check JDT help form more informations)
  • ‚Export-Package’ – package in which you have your source code.
  • ‚Bundle-ClassPath’ – build classes or libraries you want to also include to plugin binary file (will be extended further).

Handler class

The last but not least is java class for handling the click action described in plugin.xml.

public class Convert extends AbstractHandler {

	public Object execute(ExecutionEvent arg0) throws ExecutionException {
		IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveMenuSelection(arg0);
		try {
			Object firstElement = selection.getFirstElement();
			IProjectNature resource = (IProjectNature) firstElement;
			IPath path = resource.getProject().getLocation();

			IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(arg0);
			MessageDialog.openInformation(window.getShell(), "Selected Project", path.toOSString());
		} catch (Exception e) {
		return null;

	private void showErrorMessage(Exception e) {

	private void showErrorMessage(String message) {
		MessageDialog.openError(new Shell(), "Eclipse Maven Plugin", message);


This simple code just shows dialog with project path message in it.




Wprowadź swoje dane lub kliknij jedną z tych ikon, aby się zalogować:


Komentujesz korzystając z konta Wyloguj / Zmień )

Zdjęcie z Twittera

Komentujesz korzystając z konta Twitter. Wyloguj / Zmień )

Facebook photo

Komentujesz korzystając z konta Facebook. Wyloguj / Zmień )

Google+ photo

Komentujesz korzystając z konta Google+. Wyloguj / Zmień )

Connecting to %s