I am looking for a step by step guide to convert jar into an OSGi bundle using the eclipse bndtools plugin. I know it is possible to do it with bnd using the command line but would be nice to know how to do the same via the IDE.
I might be missing something but this tutorial only explains how to create a project from scratch.
There is basically no difference. A JAR is a bundle and a bundle is a JAR, the formats are identical. However, a useful bundle requires OSGi metadata in its manifest so that an OSGi framework can manage the visibility of classes between bundles.
The bnd.bnd file describes and configures the module: Bundle-Name: Greeting API Bundle-SymbolicName: com.liferay.docs.greeting.api Bundle-Version: 1.0.0 Export-Package: com.liferay.docs.greeting.api. The module's name is Greeting API. Its symbolic name–a name that ensures uniqueness–is com.
OSGi is a Java framework for developing and deploying modular software programs and libraries. Each bundle is a tightly coupled, dynamically loadable collection of classes, jars, and configuration files that explicitly declare their external dependencies (if any).
Follow the article Create Eclipse plugins (OSGi bundles) from standard jar to achieve this. Though this approach does not use Bnd, but you would be able to achieve what you want.
In short you can do following:
Create a new Plugin project by selection File-> New -> Project...-> Plug-in Development -> "Plug-in from Existing JAR Archives"
Select jars you want to have in this new plugin(bundle). Enter other plugin data(name, version, id etc.).
Uncheck the flag Unzip the JAR archive into the project
. Press then finish.
Unchecking the checkbox Unzip the JAR archive into the project
, prevents extracting class files from the Jar which is usually not necessary.
EDIT :
To Export your bundle to install it into a OSGi runtime. Select your bundle and choose File -> Export -> Plug-in Development -> "Deployable plug-ins and fragment"
.
Uncheck the checkbox to Export source.
-classpath: jar/htmlcleaner-2.2.jar, jar/htmlcleaner-2.2-src.zip
Export-Package: org.htmlcleaner.*;version=1.0
Import-Package: org.apache.tools.ant;resolution:=optional,\
org.jdom;resolution:=optional,\
*
Bundle-Version: 2.2.1
After saving this file, look in the generated directory, voila, there is your bundle! You can reuse the same project for any number of bundles you want to wrap.
You can then release the bundle to one of the repositories. Select the bnd.bnd file and select Release Bundle with the context menu.
Edit: NB You can't directly use a 'wrap' project from other projects, since Eclipse needs the source tree for that to work. There are 2 workarounds for this:
https://github.com/bndtools/bndtools/wiki/How-to-Wrap-Bundles
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