Skip to end of metadata
Go to start of metadata

Java archive (JAR) to OSGi bundle converter is a standalone tool that can be used for products based on Carbon 5.0.0 Kernel (WSO2 Carbon 5.0.0 platform). The implementation of this tool has been added to the freshly introduced tools Maven module of the WSO2 Carbon 5.0.0 platform.

The need for this functionality arose due to the availability of third-party Java archive (JAR) files, which may not have their corresponding OSGi bundle implementation. In order to deploy them in the Carbon platform, these Java archive files need to be in their corresponding OSGi bundle form. The primary purpose of this tool is to convert JAR files to their corresponding OSGi bundle form. 

Unlike a JAR file, an OSGi bundle is simply not a single application packaged into a single JAR file, but utilizes a modular approach in forming an application. An OSGi bundle contains class files, resource files similar to a JAR file. In addition, it must contain extra metadata, which are absent in a JAR file. These metadata are primarily used to declare the contained packages that are externally visible from the bundle and also to declare for the external packages on which the bundle depends. Hence, within the implementation, we primarily generate the following files, which are copied along with the original JAR file to the OSGi bundle.

  • MANIFEST.MF, which holds the metadata generated using the original JAR file.
  • A p2.inf file, which holds simple instructions to run the bundle(s) by default in the OSGi framework.

The folder structure within the OSGi bundle is as follows:



    • p2.inf

  • original_jar_file.jar

This functionality was previously implemented (for example in wso2/carbon-kernel master 4.5.0) as part of the https://github.com/wso2/carbon-kernel/tree/4.5.x/core/org.wso2.carbon.server module and was executed during server startup. However, with the increasing need to improve the server startup time, we have decided to separate this functionality from the https://github.com/wso2/carbon-kernel/tree/4.5.x/core/org.wso2.carbon.server module and integrate it to the WSO2 Carbon 5 platform as a separate tool under the freshly introduced https://github.com/wso2/carbon-kernel/tree/master/tools module.

Running the tool

This tool can be executed to convert the desired Java archive (.jar) file(s) to their corresponding OSGi bundle form, at a desired file system destination. You can execute the relevant script as shown below.

  1. Open a terminal.
  2. Navigate to the <PRODUCT_HOME>/bin directory. This scripts for executing this tool are stored in this folder.
  3. Execute the relevant script:
    • In a Unix system:  sh jartobundle.sh [source jar file/source directory containing jar files] [destination directory] 
    • Windows platform: jartobundle.bat [source jar file/source directory containing jar files] [destination directory]


Note that the required file permissions are considered when reading source JARs and the destination directory.

  • No labels