How to make OSGi plugins deployable on a p2-repo

Ajay Lamba
2 min readSep 28, 2022

--

There are different ways to convert jars to plugins for use in OSGi/RCP based applications. There is a very good maven plugin to convert the jars available on maven repo to plugins automatically. But there are times when the required jar is not available on maven and we have to convert the jar to plugin manually. By the way, this articles explains how to convert jars to plugins using eclipse project.

Once you have the plugins ready, you need to host them on a repo to use them in active target of the application. You can make the plugins deployable using the following steps:

  1. Run the following command where C:/source is the location where converted plugins are present and C:/destination is the location where you want the final content to be stored —

java -jar D:/Setup/eclipse-jee-2020–06-R-win32-x86_64/eclipse/plugins/org.eclipse.equinox.launcher_1.5.700.v20200207–2156.jar -application org.eclipse.equinox.p2.publisher.FeaturesAndBundlesPublisher -metadataRepository file:/C:/destination -artifactRepository file:/C:/destination -source /C:/source -configs gtk.linux.x86 -compress -publishArtifacts

2. Create category.xml file with following content and put it at the C:/destination location —

<?xml version="1.0" encoding="UTF-8"?>
<site>
<category-def name="all" label="P2 Repo"/>
<iu>
<category name="all"/>
<query><expression type="match">providedCapabilities.exists(p | p.namespace == 'osgi.bundle')</expression></query>
</iu>
</site>

3. Run the following command —

D:/Setup/eclipse-jee-2020–06-R-win32-x86_64/eclipse/eclipse -debug -consolelog -nosplash -verbose -application org.eclipse.equinox.p2.publisher.CategoryPublisher -metadataRepository file:/C:/destination -categoryDefinition file:/C:/destination/category.xml

4. Once you have the 4 things — 1. plugins folder, 2. artifacts.jar, 3. content.jar and 4. category.xml, you can upload these to any cloud location (e.g. Amazon S3) and access the link of the location to use in the ‘active target’ of the application.

Happy coding!!

--

--

Ajay Lamba

Decade of development experience. Passionate for best coding practices.