This article describes how to use Java libraries for Eclipse plug-in and OSGi development.

1. Using Java libraries in Eclipse plug-ins and OSGi bundles

Java libraries are delivered as JAR files. Eclipse plug-ins and OSGi based applications require additional meta-data in the META-INF/MANIFEST.MF file of libraries which they consume. In case a Java library does not provide the additional meta-data, you can add it via multiple ways. As the time of the writing, the easiest is to use the Eclipse Maven (M2E) extension to add such libraries to your target platform. M2E allows to convert non OSGi Java libraries automatically if they are part of the target platform.

You have several ways to convert a JAR file to an plug-in:

  • Use the Eclipse Maven M2e extension to add Maven libraries to your target platform

  • Manually convert the JAR file to a plug-in via an Eclipse wizard

  • Use Gradle plug-ins to converts JARs

  • Use Maven plug-ins to convert JARs

This article has been updated to describe only the M2E extension for the usage of the target platform, as this is the easiest and best A target platform containing m2e extensions is also supported by the Maven Tycho build as of version 2.2.

2. Installation

To use the Maven library integration in your target platform you have to install the corresponding tooling into your IDE.

You can use the following update site to install it via Help  Install New Software.

Install m2e PDE Integration, this will also install the basic m2e functionality.

java libraries osgi10

Restart your IDE after the installation.

3. Prerequisites

The following assumes that you already setup a target platform for development.

Perform Setting up a target platform if you have not yet done so.

4. Exercise: Make a Maven library available for plug-in development

In this exercise you add a standard library to your target platform.

4.1. Add GSON library from Maven to your target platform

Open your target platform definition file and press the Add…​ button on the first tab.

Select Maven in the following dialog.

add java library to targetplatform20

The GSON Maven coordinates we use are listed below.

add java library to targetplatform30

If you copy a Maven dependency into the clipboard before pressing the add button, the information is used to populate the wizard.

Select Compile scope and press the Finish button.

The Dependencies Scope simply defines if dependent artifacts are included or only the master artifact itself.

You can now use the library for your plug-in development, even if the original artifact did not contain the OSGi meta-data.

4.2. Validate availability of the library

To test if the library is available for you to develop, open one manifest file for an existing plug-in and switch to the dependency tab. Press Add…​ and ensure that you can add the library as dependency.

add java library to targetplatform40

Sometimes you have to restart the IDE to make the update of the target platform available for the MANIFEST.MF editor.