The "convert-jar-to-bundle" Task

The convert-jar-to-bundle task is used to convert normal JARs into OSGi bundles. This is useful when OSGi-ifying third-party libraries.

Example 3.2. Example using convert-jar-to-bundle

<project name="thirdparty" default="all">

  [..]
  <load-bundle-descriptor descriptor="${basedir}/commons-id/bundle.xml"/>
  <property name="commons-id-org-version" value="0.1-SNAPSHOT"/>      
  <property name="commons-id-version" value="0.1.0.SNAPSHOT"/>
  
  <convert-jar-to-bundle
        file="${basedir}/commons-id-${commons-id-org-version}.jar"
        targetfile=
          "${build.dir}/${osgi-bundle.symbolic-name}-${commons-id-version}.jar"
        descriptor="${basedir}/bundle.xml">
    <attribute name="Bundle-Version" value="${commons-id-version}"/>
  </convert-jar-to-bundle>
  [..]
</project>

In this example, Apache Commons Id is converted to an OSGi bundle. You will note how its version number is being replaced by a valid OSGi version number. The load-bundle-descriptor task is used to retrieve the symbolic name of the bundle from the bundle descriptor to use it as part of the target filename of the bundle (${osgi-bundle.symbolic-name}).

The file and descriptor attributes as well as the nested attribute element are the same as for the bundle-manifest task.

The targetfile attribute specifies the target filename of the converted JAR. If it is omitted, the original JAR file will be replaced.