How to add OSGI bundle to Eclipse RCP project

Is using the Plugin from Existing JAR Archives wizard in Eclipse the correct way to add an OSGi bundle to an Eclipse RCP project? I understand that Eclipse RCP uses OSGi bundles and that this wizard effectively repackages the JARs to make them into an OSGi bundle, but what if the MANIFEST.MF file already contains the OSGi packaging information?

As an example I want to add the Jersey REST Client to an RCP project and the MANIFEST.MF for the jersey-client.jar contains the following

Manifest-Version: 1.0
Bnd-LastModified: 1504605074705
Build-Jdk: 1.8.0_144
Built-By: pavel
Bundle-Description: Jersey core client implementation
Bundle-DocURL: http://www.oracle.com/
Bundle-License: https://oss.oracle.com/licenses/CDDL+GPL-1.1, https://
 oss.oracle.com/licenses/CDDL+GPL-1.1
Bundle-ManifestVersion: 2
Bundle-Name: jersey-core-client
Bundle-SymbolicName: org.glassfish.jersey.core.jersey-client
Bundle-Vendor: Oracle Corporation
Bundle-Version: 2.26.0
Created-By: Apache Maven Bundle Plugin
Export-Package: org.glassfish.jersey.client;uses:="javax.inject,javax.
 net.ssl,javax.ws.rs,javax.ws.rs.client,javax.ws.rs.core,javax.ws.rs.e
 xt,org.glassfish.jersey,org.glassfish.jersey.client.spi,org.glassfish
 .jersey.internal,org.glassfish.jersey.internal.inject,org.glassfish.j
 ersey.internal.util,org.glassfish.jersey.internal.util.collection,org
 .glassfish.jersey.message,org.glassfish.jersey.message.internal,org.g
 lassfish.jersey.spi";version="2.26.0",org.glassfish.jersey.client.aut
 hentication;uses:="javax.ws.rs,javax.ws.rs.client,javax.ws.rs.core";v
 ersion="2.26.0",org.glassfish.jersey.client.filter;uses:="javax.ws.rs
 .client,javax.ws.rs.core";version="2.26.0",org.glassfish.jersey.clien
 t.spi;uses:="javax.net.ssl,javax.ws.rs.client,javax.ws.rs.core,org.gl
 assfish.jersey.client,org.glassfish.jersey.process";version="2.26.0"
Import-Package: javax.annotation;version="[1.2,2)",javax.inject;versio
 n="[1.0,2)",javax.net.ssl,javax.ws.rs;version="[2.1,3)",javax.ws.rs.c
 lient;version="[2.1,3)",javax.ws.rs.core;version="[2.1,3)",javax.ws.r
 s.ext;version="[2.1,3)",org.glassfish.jersey;version="[2.26,3)",org.g
 lassfish.jersey.client.spi,org.glassfish.jersey.internal;version="[2.
 26,3)",org.glassfish.jersey.internal.guava;version="[2.26,3)",org.gla
 ssfish.jersey.internal.inject;version="[2.26,3)",org.glassfish.jersey
 .internal.l10n;version="[2.26,3)",org.glassfish.jersey.internal.spi;v
 ersion="[2.26,3)",org.glassfish.jersey.internal.util;version="[2.26,3
 )",org.glassfish.jersey.internal.util.collection;version="[2.26,3)",o
 rg.glassfish.jersey.message;version="[2.26,3)",org.glassfish.jersey.m
 essage.internal;version="[2.26,3)",org.glassfish.jersey.model.interna
 l;version="[2.26,3)",org.glassfish.jersey.process;version="[2.26,3)",
 org.glassfish.jersey.process.internal;version="[2.26,3)",org.glassfis
 h.jersey.spi;version="[2.26,3)",org.glassfish.jersey.uri;version="[2.
 26,3)"
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"
Tool: Bnd-3.2.0.201605172007

Is using the Plugin from Existing JAR Archives wizard the correct way to add this dependency to an RCP project or should a different method be used if it is already an OSGi bundle?

Answer

The Plugin from Existing JAR Archives wizard is meant to create a bundle, including OSGi metadata, from a plain JAR that is not packaged as an OSGi bundle.

Thus, in your case, you can go with the jersey-client.jar as it is.

Usually, the more interesting question is where to provision the bundle so that it can be consumed easily from your RCP application. If you are using target platform definitions and/or Tycho for CI builds, you will probably want to be able to fetch the bundle from a p2 repository.

The p2-maven-plugin may help here to create a p2 repository for the Jersey bundle and possibly other dependencies.

The Eclipse Orbit project provides a p2 repository with bundles commonly used by other Eclipse projects. There is also a Jersey client listed in the table of contents. Maybe this one already suits your needs.

Leave a Reply

Your email address will not be published. Required fields are marked *