Support free tutorials









vogella training Training Books



How to create Eclipse plugins from jars - Tutorial

Lars Vogel

Version 1.2

19.09.2014

Converting jars to Eclipse plugins

This article describes how to create Eclipse plugins (OSGi bundles) from standard Java libraries delivered as JAR files. This article is based on Eclipse 4.4.


Table of Contents

1. JAR files without OSGi meta-data
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. JAR files without OSGi meta-data

If a JAR file does not contain the OSGi meta-data in the META-INF/MANIFEST.MF file, it cannot be directly consumed by other Eclipse plug-ins.

If you want to use such standard Java libraries in other Eclipse plug-ins you have to convert them also into a plug-in. After the conversion the resulting JAR file can still be used in a non OSGi runtime, e.g., a Java webserver. The Java runtime will simply ignore the additional OSGi meta-data.

Eclipse provides a wizard to convert a JAR file with OSGi meta-data to a plug-in. The usage of this wizard is demonstrated in Section 2, “Integrating external jars / third party libraries”.

Note

If you repackage a jars into a plug-in it is wise to check if the license allows this. You should also try to contact the author the the software and ask if he can integrate the OSGi meta-data directly in his library.

2. Integrating external jars / third party libraries

The following gives an example how to convert a standard Java JAR to an Eclipse plug-in.

2.1. Create a plug-in project for your jar

Create a new plug-in project by selecting FileNewProjectPlug-in DevelopmentPlug-in from Existing JAR Archives.

Add the JAR files you want to have in this new plug-in. Press next.

Enter a name and a version for your new plug-in. Uncheck the Unzip the JAR archive into the project flag. Unchecking this flag prevents that the class files are extracted from the JAR file which is not necessary to use them.

Afterwards press the Finish button in the wizard.

You have now create a new plug-in for the selected JAR files. Open the file MANIFEST.MF and validate that all required package are exported on the tab Runtime. All the packages from your JAR files should be included in the exported packages as OSGi will otherwise prevent other plug-ins from accessing them.

2.2. Using the new plug-in project

In the plug-in project which should access the library, open the MANIFEST.MF file and select the Dependencies tab. Add the new plug-in as dependency.

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. It will help to maintain our content and our Open Source activities.

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