vogella.de

Follow me on twitter
About Lars Vogel
Flattr this

How to create Eclipse plugins from jars

Lars Vogel

Version 0.3

07.06.2010

Revision History
Revision 0.126.07.2009Lars Vogel
Separated from http://www.vogella.de/articles/RichClientPlatform/article.html
Revision 0.217.10.2009Lars Vogel
Minor rework
Revision 0.307.06.2010Lars Vogel
Update to Eclipse 3.6 (Helios)

Converting jars to Eclipse plugins

This article describes how to create Eclipse plugins (OSGi bundles) from standard Java libraries delivered as jars. This article is based on Eclipse 3.6 (Helios).


Table of Contents

1. Overview
2. Integrating external jars / third party libraries
2.1. Create a plugin project for your jar
2.2. Using the new plugin project
3. Thank you
4. Questions and Discussion
5. Links and Literature
5.1. Source Code
5.2. vogella Resources

1. Overview

The standard deployment format for Java is a .jar file. A jar file is a zip file which contains the necessary resources to use the Java libraries, e.g. the class files.

In Eclipse RCP and Eclipse plugin development you work with Eclipse bundles or OSGi bundles . If you want to use standard Java libraries (jars) in this environment you have to convert them to a plugin. After creating a new plugin project, you have to export the necessary packages for these jars and and add the new plugin as a dependency to the plugin which is using the functionality provided by the new plugin.

If you repackage a jars into a plugin it is wise to check if the license allows this.

2. Integrating external jars / third party libraries

The following gives an example how to convert jars to Eclipse plugins.

2.1. Create a plugin project for your jar

Create a new Plugin project by selection File-> New -> Project...-> Plug-in Development -> "Plug-in from Existing JAR Archives"

Add the jars you want to have in this new plugin. Press next.

Maintain a name and a version for this plugin. Uncheck the flag "Unzip the JAR archive into the project". Press then finish. Unchecking the flag "Unzip the JAR archive into the project" prevents that the class files are extracted from the Jar which is usually not necessary.

You have now bundled your jars into a new plugin. Open the file "MANIFEST.MF" and validate that all required package are exported on the tab "Runtime". All the packages from your jars should be included in the exported packages as OSGi will otherwise present other plugins from accessing them.

2.2. Using the new plugin project

In the plugin project which should use the library, select now select your plugin.xml and the tab dependencies. Under required Plug-ins press add and add your generated plugin as a dependency to your RCP application. This will make the classes from the jar available to your plugin.

3. Thank you

Thank you for practicing with this tutorial.

I maintain this tutorial in my private time. If you like the information please help me by using flattr or donating or by recommending this tutorial to other people.

Flattr this

4. Questions and Discussion

Before posting questions, please see the vogella FAQ . If you have questions or find an error in this article please use the www.vogella.de Google Group . I have created a short list how to create good questions which might also help you. .

5. Links and Literature

5.1. Source Code

Source Code of Examples