Convert a JAR file into an OSGi bundle

Last update: 2024-01-18

To convert a Java Archive (JAR) file into an OSGi bundle, follow the steps to create an OSGi bundle from the attached junit-4.4.jar, as described in this article below.



Experience Manager


How do I convert an existing Java Archive (JAR) file into an Open Service Gateway Initiative (OSGi) bundle?


  1. Start by creating a JAR’s manifest file:

    Manifest-Version: 1.0
    Created-By: myself
    Bundle-ManifestVersion: 2
    Bundle-Name: JUnit 4.4 bundle
    Bundle-Description: Package junit 4.4 in an OSGi bundle
    Bundle-Version: 4.4.0
    Bundle-ClassPath: .,junit-4.4.jar
    Bundle-SymbolicName: org.junit.framework
    Export-Package: junit.framework,junit.extensions,org.junit.runner,org.junit,junit.textui
    • Bundle-ClassPath header is set to allow embedding the original jar as is. Make sure its value matches the filename of the jar that you are going to embed in the bundle.
    • Export-Package is a list of packages contained in the jar that you would like to make available to other bundles running in the OSGi Container.
  2. JAR file

    Get the jar file.

  3. Create the bundle jar file by running the following command:

    jar cvfm junit-4.4-bundle.jar manifest.txt junit-4.4.jar

    Where manifest.txt is the name of the manifest file created above.

That’s it - the resulting jar file is an OSGi bundle the exports the packages listed in Export-Package above, using the classes of the embedded junit-4.4.jar.

On this page