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.
The key difference with OSGi is that a JAR is now all private, adding metadata in the manifest makes it a bundle that can safely share with other bundles. OSGi makes sure violations are detected ahead of time. yes, it is a normal JAR. However, in a JavaEE app it will of course act as a JAR and not as a bundle.
worth to notice if jars are not osgi bundles. You can not use jar directly in AEM, need to converted the Jar into bundle with help of the link "https://helpx.adobe.com/experience-manager/kb/ConvertAJarIntoOsgiBundle.html" , Now your bundle is ready to be uploaded into AEM through felix console. java. lang.
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.
The Eclipse Bundle Recipe project provides a Maven based approach for adding OSGi meta data to JARs consumed from a Maven repository. Despite the name it doesn't use Eclipse.
At its core, it uses the bnd tool. This tool is like a swiss army knife. It analyzes jars and class files and properly calculate package import and exports. You should use bnd for converting proprietary jars yourself. It's available in Maven Central.
If you're using Maven then you can use the Maven Bundle Plugin to inline or embed dependencies in a OSGi bundle:
http://felix.apache.org/documentation/subprojects/apache-felix-maven-bundle-plugin-bnd.html#embedding-dependencies
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With