Karaf Archives (KAR)

Karaf provides a specific archive format named the KAR (Karaf ARchive).

Basically, the kar format is a jar (so a zip file) which contains a set of feature descriptor and bundle jar files.

For instance, a kar looks like:

  • my-features-1.xml

  • bundle1.jar

  • bundle2.jar

  • bundle3.jar

all packaged in zip format.

Create a kar archive

You can create a kar file by hand, just by zip compressing a directory representing the kar content.

You can also use the Karaf features maven plugin. The features maven plugin provides an create-kar goal.

The kar-archive goal:
1. Reads all features specified in the features descriptor.
2. For each feature, it resolves the bundles defined in the feature.
3. All bundles are packaged into the kar archive.

For instance, you can use the following POM to create a kar:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>my.groupId</groupId>
    <artifactId>my-kar</artifactId>
    <version>1.0</version>
    <packaging>pom</packaging>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.karaf.tooling</groupId>
                <artifactId>features-maven-plugin</artifactId>
                <version>2.2.8</version>
                <executions>
                    <execution>
                        <id>create-kar</id>
                        <goals>
                            <goal>create-kar</goal>
                        </goals>
                        <configuration>
                            <featuresFile>src/main/resources/features.xml</featuresFile>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

For the example, the features descriptor is very simple:

<?xml version="1.0" encoding="UTF-8"?>
<features>

   <feature name="my" version="1.0">
      <bundle>mvn:commons-collections/commons-collections/3.2.1</bundle>
   </feature>

</features>

To create the kar archive, simply type:

mvn install

and you will have your kar in the target directory.

Deploy a kar archive

Karaf provides a KAR deployer:

karaf@root> la|grep -i archive
[  12] [Active     ] [Created     ] [   30] Apache Karaf :: Deployer :: Karaf Archive (.kar) (2.2.4)

It's a core deployer (you don't need to install additional features).

To deploy a kar, simply drop the kar into the deploy directory. The KAR Deployer will deploy all the kar content starting
from the features descriptor.

The KAR Deployer creates a repository dedicated to your kar (in the $/local-repo) and register the features
descriptor. You can now see your feature available for installation:

karaf@root> features:list|grep -i my
[uninstalled] [1.0             ] my                            repo-0

Now you can use any commands available on features:

karaf@root> features:install my