mvn:install feature xml from the command-line

Sometimes, in the dark corners of corporate IT, you only have the local Maven repository in Karaf to hold your precious artifacts, far away from your build environment. Deploying to Karaf with mvn urls still beats dumping bundles into the deploy directory, so let’s use the ${karaf.home}/data/repository.

Bundles are straight-forward:

mvn install:install-file
-DgroupId=nl.beroco
-DartifactId=cool-bundle
-Dversion=1.0.0
-Dpackaging=jar
-DlocalRepositoryPath=/karaf-install-dir/data/repository
-Dfile=cool-bundle-1.0.0.jar

And then the bundle can be installed in Karaf with:

osgi:install mvn:nl.beroco/cool-bundle/1.0.0

Features however, should be treated as attachments to artifacts in Maven, and this can be done using the ‘classifier’ parameter. The artifact itself doesn’t even have to have any content, but usually the build of a jar with only the feature xml is configured in the pom for this reason.

But I’m gonna go for a totally bogus artifact cool-repo, with the feature-xml as an attachment.

This is the cool-repo.xml itself (allows for multiple features):

<features name="cool-repo">
  <feature name="cool-feature" version="1.0.0">
    <feature prerequisite="true">lib-feature</feature>
    <feature prerequisite="true">camel-beanio</feature>
    <bundle>mvn:nl.beroco/cool-bundle/1.0.0</bundle>
  </feature>
</features>

And it can be installed into the local repo with:

mvn -X install:install-file
-Dpackaging=xml
-DgroupId=nl.beroco
-DartifactId=cool-repo
-Dversion=1.0.0
-Dfile=cool-repo.xml
-DlocalRepositoryPath=/karaf-install-dir/data/repository
-Dclassifier=features
-Dtype=xml

Disclaimer: I found this working solution only after some trial-and-error processing.

And after that you should be able to install the feature-repository:

features:addurl mvn:nl.beroco/cool-repo/1.0.0/xml/features

and use the features with:

features:install cool-feature