Support free tutorials:

vogella training Training Books

How to create Eclipse plugins from jars - Tutorial

Lars Vogel

Version 1.1


Revision History
Revision 0.1 26.07.2009 Lars
Revision 0.2 - 1.1 17.10.2009 - 12.06.2011 Lars
Minor rework

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 plug-in project for your jar
2.2. Using the new plug-in project
3. Support this website
3.1. Thank you
3.2. Questions and Discussion
4. Links and Literature
4.1. Source Code
4.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 plug-in 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 plug-in project, you have to export the necessary packages for these jars and add the new plug-in as a dependency to the plug-in which is using the functionality provided by the new plugin.

If you repackage a jars into a plug-in 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 plug-in 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 plug-in project

In the plug-in 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 plug-in as a dependency to your RCP application. This will make the classes from the jar available to your plugin.

3. Support this website

This tutorial is Open Content under the CC BY-NC-SA 3.0 DE license. Source code in this tutorial is distributed under the Eclipse Public License. See the vogella License page for details on the terms of reuse.

Writing and updating these tutorials is a lot of work. If this free community service was helpful, you can support the cause by giving a tip as well as reporting typos and factual errors.

3.1. Thank you

Please consider a contribution if this article helped you.

Flattr this

3.2. Questions and Discussion

If you find errors in this tutorial, please notify me (see the top of the page). Please note that due to the high volume of feedback I receive, I cannot answer questions to your implementation. Ensure you have read the vogella FAQ as I don't respond to questions already answered there.

4. Links and Literature

4.1. Source Code

Source Code of Examples

4.2. vogella Resources

vogella Training Android and Eclipse Training from the vogella team

Android Tutorial Introduction to Android Programming

GWT Tutorial Program in Java, compile to JavaScript and HTML

Eclipse RCP Tutorial Create native applications in Java

JUnit Tutorial Test your application

Git Tutorial Put all your files in a distributed version control system