I have a JAR file that I need to convert to an OSGi bundle. I do not have the original source code for the JAR file.
I tried to use the answers from: How to create OSGi bundle from jar library?
However, they are pretty outdated.
Edit: I need to convert several, but a fixed number of jars.
Option 1 - use bnd-platform to build your OSGi bundles when expecting frequent additions/updates of Jars, or when you can retrieve your dependencies from Maven repositories
We use bnd-platform (I am also the author) to manage third party dependencies and create OSGi bundles from them. You can use it with both dependencies retrieved from Maven repositories and local Jars (see the README). If you regularly add or update your dependencies I would suggest that you try bnd-platform. It's a plugin for Gradle, you can easily start with this template - just add your Jar files and provide the configuration as described in the project README (bundle symbolic names, versions) and run gradlew bundles
.
Option 2 - use bnd to build your OSGi bundles when you do it once or additions/updates are seldom
If you only do this process once or seldom, a simple way to create an OSGi bundle from an existing Jar is to directly use bnd on the command line. The only thing you need is Java and the bnd jar. You can use wrap
to try to automatically wrap a jar or create a .bnd
file with instructions for bnd (e.g. to only export specific packages).
Example .bnd file:
-classpath: lib/trove-2.0.4.jar
-output: gnu.trove-2.0.4.jar
Export-Package: *;-split-package:=merge-last;-noimport:=true
Import-Package: *
Bundle-Version: 2.0.4
Bundle-Name: GNU Trove Collections Plug-in
Bundle-SymbolicName: gnu.trove
Example call:
java -jar <path to bnd>.jar trove-2.0.4.bnd
The bnd Jar download is no longer offered directly through the web site, a good alternative is to download it from Maven Central.