Hello again,
In the interests of clarity, I have some input to the Karaf community on how to
do this:
Recommended process for creating a Karaf features definition file
It is practical to create a karaf distribution for your own organisation or
pleasure.
The following process is a recommended approach to keep the bundle dependencies
in sync with the dependencies defined within your pom.
a) Include the the depend-maven-plugin into your pom build process, to generate
a dependencies file for all dependencies within your project. (This step is
required both for this process and for Pax exam, so save yourself some trouble
and include it in your parent pom, to use it within all maven projects in your
build). The file generated by the pom plugin snippet below is
${basedir}/target/classes/META-INF/maven/dependencies.properties.
<plugins>
<plugin>
<groupId>org.apache.servicemix.tooling</groupId>
<artifactId>depends-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-depends-file</id>
<phase>generate-sources</phase>
<goals>
<goal>generate-depends-file</goal>
</goals>
</execution>
</executions>
</plugin>
b) Define a maven filter using the properties defined within your
dependencies.properties file. Then enable resource filtering within your
resources directory (or, as is the case below, a new resources directory within
the maven project, called src/main/filtered-resources).
<build> <filters>
<filter>${basedir}/target/classes/META-INF/maven/dependencies.properties</filter>
</filters> <resources> <resource>
<directory>src/main/filtered-resources</directory> <filtering>true</filtering>
<includes> <include>**/*</include> </includes> </resource> </resources>
c) Within the filtered-resources directory, create a Karaf features file (say
"my-features.xml"). Within this file, use the syntax
${[groupId]/[artifactId]/version} (for example ${org.aspectj/aspectjrt/version}
to create a token which substitutes the version of the named artifact with its
value, defined within the pom. In plain english:
c-1) If you want to include a pre-made OSGi bundle, use the syntax:
<bundle>mvn:joda-time/joda-time/${joda-time/joda-time/version}</bundle>
c-2) If you want to wrap a non-OSGi-enabled bundle, use the syntax:
<bundle><![CDATA[wrap:mvn:org.aspectj/aspectjrt/${org.aspectj/aspectjrt/version}$Bundle-Version=${org.aspectj/aspectjrt/version}&Bundle-SymbolicName=aspectjrt&Blarg-HeaderValue=lennart]]</bundle>
Note that the <![CDATA[ .... ]]> section is necessary to avoid problems in the
wrapping process and in the consequent Karaf launch.
c-3) If you want to include any token normally defined within the maven pom,
simply use the maven variable definition, such as: ${project.version}
d) Note that the pax construct will transform all Key=Value pairs after the &
character in a wrap:-ped bundle into Manifest headers.
Inspecting the headers of the newly deployed example bundle (aspectjrt, in this
case) yields a custom manifest header with the key "Blarg-HeaderValue" and the
value "lennart" in addition to symbolic name and version.
karaf@root> osgi:headers 119
You are about to access system bundle 119. Do you wish to continue (yes/no):
yes
aspectjrt (119)
---------------
Manifest-Version = 1.0
Blarg-HeaderValue = lennart
Bnd-LastModified = 1331195844625
Tool = Bnd-0.0.357
Generated-By-Ops4j-Pax-From =
wrap:mvn:org.aspectj/aspectjrt/1.6.12$Bundle-Version=1.6.12&Bundle-SymbolicName=aspectjrt&Blarg-HeaderValue=lennart
Created-By = 1.6.0_29 (Apple Inc.)
Bundle-Name = aspectjrt
Bundle-SymbolicName = aspectjrt
Bundle-Version = 1.6.12
Bundle-ManifestVersion = 2
... the rest of the manifest headers omitted ...
--
// Bästa hälsningar,
// [sw. "Best regards,"]
//
// Lennart Jörelid, Systems Architect
// email:
[email protected]<mailto:[email protected]>
// cell: +46 708 507 603
// skype: jgurueurope