How to convert jar to OSGi bundle using eclipse and bndtools

前端 未结 3 990
陌清茗
陌清茗 2020-12-03 03:57

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 bu

3条回答
  •  渐次进展
    2020-12-03 04:21

    1. Just create a new project in bndtools for all (or related) jars that you want to convert.
    2. Give this project a name that will be the prefix of the bundle symbolic name of the converted jars. E.g. if your company is acme, call the project 'com.acme'
    3. Download the jar and sources in a jar directory
    4. Create a new bundle descriptor with a -classpath entry (File/New/Bundle Descriptor), for example:

    -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:

    • Put the wrapped bundled in a repository and use it from there (as described above)
    • Unpack the source tree in the src folder of the project

    https://github.com/bndtools/bndtools/wiki/How-to-Wrap-Bundles

提交回复
热议问题