Java, Eclipse and Web programming Tutorials
Follow me on twitter About Lars Vogel

Converting Java libraries (jars) to Eclipse plugins / OSGi bundles - Tutorial

Lars Vogel

Version 0.2

17.10.2009

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

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.5 (Eclipse Galileo).


Table of Contents

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

1. Overview

In Eclipse RCP and Eclipse plugin development you work with Eclipse bundles or OSGi bundles .

This article describes how to convert standard Java libraries delivered as jars to Eclipse plugins / OSGi bundles.

2. Integrating external jars / third party libraries

2.1.  Overview

Java bundles packages into jars. Eclipse RCP requires that these jars are bundled into plugin project. The following will describes how to integrated these jars into an Eclipse RCP product.

You create a plugin project for these jars and and add this plugin as dependency to your Eclipse RCP application / product.

Tip

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

2.2. 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.

Tip

Uncheck the flag "Unzip the JAR archive into the project" prevents that the class files are extracted from the Jar.

You have now bundled your jars into a new plugin. Check the MANIFEST.MF on the tab runtime. All the packages from your jars should be included in the exported packages as your Eclipse RCP application will access these packages.

In the plugin project in which you want to use the libraries you can 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.

Please note that I maintain this website in my private time. If you like the information I'm providing please help me by donating.

4. Questions and Discussion

For questions and discussion around this article please use the www.vogella.de Google Group. Also if you note an error in this article please post the error and if possible the correction to the Group.

I believe the following is a very good guideline for asking questions in general and also for the Google group How To Ask Questions The Smart Way.

5. Links and Literature

5.1. Source Code

http://www.vogella.de/code/codeeclipse.html Source Code of Examples