javaosgibnd

How to specify class files with bnd


I already successfully used the standalone bnd tool to create an OSGi bundle from a jar file.

Now I would like to create a bundle starting from .class files. By looking at some of the official bnd documentation I couldn't find anything to do this. I guess I'm looking for something like -classpath: output.jar that could work for .class files.


Solution

  • There are different options: Workspace bndtools (includes Gradle build), Standalone Gradle, Maven, and bnd standalone. I strongly prefer the Bndtools workspace model since it is by the most user friendly. Lots of support, full fidelity with gradle without any extra work, interactive debugging, remote debugging, packaging, and active community. It is based on Eclipse.

    The following links should be able to get you started:

    Update

    If you just want to use the bnd command line you're simplifying things a lot but you also have to take care of more things. And you miss the wonderful world of bndtools :-(

    Even then, you still have a choice to make. bnd can be used to build Workspace model setups. In this case you follow the rules for the bndtools Workspace tutorials etc. In that model, you can use bnd build, compile, and many other commands in the workspace or projects directories.

    If you also want to skip those, you end up with a bnd that just generates a JAR from a bnd property file. In that case you must specify all your dependencies with:

    -classpath bin/,jar/a.jar, jar/b.jar
    

    You can then use all the Builder instructions.

    -includeresource
    Private-Package
    Export-Package
    -exportcontents
    ...
    

    All bundle headers, etc. Most verrification and building should work similar from the Bndtools workspace examples. Of course you miss launching and many other features. However, I've heard of someone that builds a large code base this way ...

    The following URL shows some examples how to use this: https://bnd.bndtools.org/chapters/160-jars.html