This article describes how to use Java libraries for Eclipse plug-in and OSGi development.
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.
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.
Install m2e PDE Integration, this will also install the basic m2e functionality.
Restart your IDE after the installation.
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.
In this exercise you add a standard library 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.
The GSON Maven coordinates we use are listed below.
<dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.8.7</version> </dependency>
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.
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.
Sometimes you have to restart the IDE to make the update of the target platform available for the MANIFEST.MF editor.