Table of Contents
The bundle-manifest
task allows you to create a JAR manifest with the necessary OSGi headers for the bundle to be created.
Example 3.1. Example using bundle-manifest
<project name="example.freespace" default="all"> [..] <!-- Build manifest from bundle descriptor and add additional entries --> <bundle-manifest file="${build.classes.dir}/META-INF/MANIFEST.MF" classes="${build.classes.dir}" descriptor="${basedir}/bundle.xml"> <attribute name="Bundle-Version" value="${version}"/> <attribute name="Bundle-Vendor" value="${implementation.vendor}"/> <attribute name="Bundle-DocURL" value="${implementation.url}"/> <attribute name="Implementation-Title" value="${Name} (${subproject-name})"/> <attribute name="Implementation-Version" value="${version}"/> <attribute name="Implementation-Vendor" value="${implementation.vendor}"/> <attribute name="Implementation-URL" value="${implementation.url}"/> </bundle-manifest> <!-- Now build the actual bundle. --> <jar jarfile="${build.dir}/${subproject-name}.jar" filesetmanifest="merge" manifestencoding="UTF-8"> <fileset dir="${build.classes.dir}"/> <metainf dir="${project-root.dir}" includes="LICENSE.txt,NOTICE.txt"/> </jar> [..] </project>
The example above shows a typical use of the bundle-manifest
task. As you can see,
the first step is to generate the manifest which is written to /META-INF/MANIFEST.MF
(in the directory where you place the compiled classes). The jar
task can then
merge that generated manifest into the final manifest that will be found in the JAR file (see filesetmanifest="merge"
).
The file
attribute specifies the manifest file to be written.
The descriptor
attribute specifies the bundle descriptor for the bundle.
The classes
attribute specifies the directory containing the compiled Java classes to be analyzed to determine all necessary imports.
Additionally, you can add a nested path
element (See Ant's path-like structures) as a child of bundle-manifest
to specify additional JAR files that will be assumed to be embedded in the bundle (under /META-INF/lib/
). These embedded
JARs will also be scanned for external dependencies. You are, however, responsible for copying these JARs to the right place in
the classes directory so they end up in the bundle/JAR and are found at runtime.
Finally, you can provide any number of header attributes
just like is possible in Ant's manifest
or jar
tasks.
It is recommended to provide at least the Bundle-Version
header so the bundle's version number is applied to all exports.
Headers specified in the bundle descriptor will override equally-named headers from the Ant task!