Search code examples
apache-karafkaraf

How to manually create a Karaf kar file from features.xml and jars


I wish to manually create a Karaf kar file.

Since I have a feature.xml file which works and jar files referenced by the feature.xml file I thought if I create a jar of this, rename it to filename.kar then it should work.

However Karaf says:

2017-02-09 14:21:50,171 | INFO  | raf-4.0.8/deploy | KarArtifactInstaller             | 27 - org.apache.karaf.deployer.kar - 4.0.8 | Found a .kar file to deploy.
2017-02-09 14:21:50,172 | INFO  | raf-4.0.8/deploy | KarArtifactInstaller             | 27 - org.apache.karaf.deployer.kar - 4.0.8 | Installing KAR file C:\home\software\apache-karaf-4.0.8\apache-karaf-4.0.8\deploy\JMScalaJS.kar

But - it does not do anything else, the feature does not become available when I do feature:list.

My JMScalaJS.kar file contains:

feature.xml
jmscalajs_2.11-0.1-SNAPSHOT.jar
neo4j-java-driver-1.0.5.jar
neo4j-ogm-osgi_2.11.jar
scaldi_2.11-0.5.8.jar

Then my feature.xml contains

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<features name="JMScalaJS" xmlns="http://karaf.apache.org/xmlns/features/v1.4.0">
    <repository>mvn:org.apache.camel.karaf/apache-camel/2.18.2/xml/features</repository>
    <feature description="JMScalaJS" version="0.1.0" name="JMScalaJS">
        <feature prerequisite="true" dependency="false">wrap</feature>
        <feature>camel-scala</feature>
        <feature>camel-core</feature>
        <feature>camel-ftp</feature>
        <feature>camel-exec</feature>
        <feature>camel-stream</feature>
        <feature>camel</feature>
        <bundle>wrap:mvn:com.jcraft/jzlib/1.1.3</bundle>
        <bundle>wrap:mvn:com.github.kxbmap/configs_2.11/0.4.4</bundle>
        <bundle>mvn:com.chuusai/shapeless_2.11/2.3.2</bundle>
        <bundle>mvn:commons-lang/commons-lang/2.6</bundle>
        <bundle>mvn:org.apache.commons/commons-exec/1.3</bundle>
        <bundle>mvn:commons-net/commons-net/3.3</bundle>
        <bundle>wrap:mvn:com.jcraft/jsch/0.1.54</bundle>
        <bundle>mvn:com.typesafe/config/1.3.1</bundle>
        <bundle>mvn:com.typesafe.scala-logging/scala-logging_2.11/3.5.0</bundle>
        <bundle>mvn:org.apache.commons/commons-collections4/4.1</bundle>
        <bundle>mvn:commons-codec/commons-codec/1.10</bundle>
        <bundle>mvn:ch.qos.logback/logback-classic/1.1.7</bundle>
        <bundle>mvn:ch.qos.logback/logback-core/1.1.7</bundle>
        <bundle>mvn:commons-logging/commons-logging/1.2</bundle>
        <bundle>wrap:mvn:commons-httpclient/commons-httpclient/3.1</bundle>
        <bundle>wrap:mvn:org.apache.lucene/lucene-sandbox/6.2.0</bundle>
        <bundle>wrap:mvn:org.apache.lucene/lucene-queries/6.2.0</bundle>
        <bundle>wrap:mvn:org.apache.lucene/lucene-core/6.2.0</bundle>
        <bundle>wrap:mvn:com.typesafe.akka/akka-http_2.11/10.0.3</bundle>
        <bundle>wrap:mvn:com.typesafe.akka/akka-http-core_2.11/10.0.3</bundle>
        <bundle>mvn:com.typesafe.akka/akka-stream_2.11/2.4.16</bundle>
        <bundle>mvn:com.typesafe/ssl-config-core_2.11/0.2.1</bundle>
        <bundle>mvn:org.reactivestreams/reactive-streams/1.0.0</bundle>
        <bundle>wrap:mvn:com.typesafe.akka/akka-parsing_2.11/10.0.3</bundle>
        <bundle>mvn:com.typesafe.akka/akka-osgi_2.11/2.4.16</bundle>
        <bundle>mvn:com.typesafe.akka/akka-camel_2.11/2.4.16</bundle>
        <bundle>mvn:com.typesafe.akka/akka-slf4j_2.11/2.4.16</bundle>
        <bundle>mvn:com.typesafe.akka/akka-actor_2.11/2.4.16</bundle>
        <bundle>mvn:org.scala-lang.modules/scala-java8-compat_2.11/0.7.0</bundle>
        <bundle>mvn:org.apache.commons/commons-lang3/3.4</bundle>
        <bundle>mvn:commons-io/commons-io/2.4</bundle>
        <bundle>wrap:mvn:io.monix/monix-cats_2.11/2.2.1</bundle>
        <bundle>wrap:mvn:org.typelevel/cats-core_2.11/0.9.0</bundle>
        <bundle>wrap:mvn:org.typelevel/cats-kernel_2.11/0.9.0</bundle>
        <bundle>wrap:mvn:org.typelevel/cats-macros_2.11/0.9.0</bundle>
        <bundle>wrap:mvn:org.typelevel/machinist_2.11/0.6.1</bundle>
        <bundle>wrap:mvn:com.github.mpilquist/simulacrum_2.11/0.10.0</bundle>
        <bundle>wrap:mvn:io.monix/monix-types_2.11/2.2.1</bundle>
        <bundle>wrap:mvn:org.typelevel/macro-compat_2.11/1.1.1</bundle>
        <bundle>mvn:org.apache.camel/camel-core-osgi/2.18.2</bundle>
        <bundle>mvn:com.sun.xml.bind/jaxb-impl/2.2.11</bundle>
        <bundle>mvn:com.sun.xml.bind/jaxb-core/2.2.11</bundle>
        <bundle>mvn:com.fasterxml.jackson.core/jackson-databind/2.8.3</bundle>
        <bundle>mvn:com.fasterxml.jackson.core/jackson-core/2.8.3</bundle>
        <bundle>mvn:com.fasterxml.jackson.core/jackson-annotations/2.8.0</bundle>
        <bundle>mvn:com.github.domino-osgi/domino_2.11/1.1.1</bundle>
        <bundle>mvn:org.apache.felix/org.apache.felix.scr/2.0.6</bundle>
        <bundle>wrap:mvn:org.codehaus.mojo/animal-sniffer-annotations/1.9</bundle>
        <bundle>mvn:org.osgi/osgi.core/6.0.0</bundle>
        <bundle>mvn:org.slf4j/log4j-over-slf4j/1.7.22</bundle>
        <bundle>mvn:org.slf4j/jcl-over-slf4j/1.7.22</bundle>
        <bundle>mvn:org.slf4j/slf4j-simple/1.7.22</bundle>
        <bundle>mvn:org.slf4j/slf4j-api/1.7.22</bundle>
        <bundle>wrap:mvn:com.lihaoyi/scalatags_2.11/0.6.1</bundle>
        <bundle>wrap:mvn:com.lihaoyi/sourcecode_2.11/0.1.1</bundle>
        <bundle>mvn:org.scala-lang/scala-compiler/2.11.8</bundle>
        <bundle>mvn:org.scala-lang.modules/scala-parser-combinators_2.11/1.0.4</bundle>
        <bundle>mvn:org.scala-lang.modules/scala-xml_2.11/1.0.4</bundle>
        <bundle>mvn:org.scala-lang/scala-reflect/2.11.8</bundle>
        <bundle>file:scaldi_2.11-0.5.8.jar</bundle>
        <bundle>file:neo4j-ogm-osgi_2.11.jar</bundle>
        <bundle>file:neo4j-java-driver-1.0.5.jar</bundle>
        <bundle>file:jmscalajs_2.11-0.1-SNAPSHOT.jar</bundle>
    </feature>
</features>

If you can tell me the minimum set of changes I need to make to make this work then that would satisfy this question as it would explain how to manually create a Karaf file from a features file and jars.


Solution

  • Standard ZIP file can be used for that (which JAR is with MANIFEST.MF file as the first file in ZIP).

    The following layout have to be used - which is same as Maven repositor layout. The reasin is Karaf uses Aether to resolve bundles, which is the engine of newer versions of maven. (As I remember later than 3.3):

    /repository - which is standard maven layout. So the bunldes have to be stored as groupId parts as directory / version / artifactId-version.jar.

    In the repository you have to store the feature repository xml file too, to be able to resolve features. Have to store same as it is on local maven repository.

    Examample of kar structure (its a fragment):

    .
    |____repository
    | |____com
    | | |____carrotsearch
    | | | |____java-sizeof
    | | | | |____0.0.4
    | | | | | |____java-sizeof-0.0.4.jar
    | | |____fasterxml
    | | | |____classmate
    | | | | |____1.2.0
    | | | | | |____classmate-1.2.0.jar
    | | | |____jackson
    | | | | |____core
    | | | | | |____jackson-annotations
    | | | | | | |____2.6.6
    | | | | | | | |____jackson-annotations-2.6.6.jar
    | | | | | |____jackson-core
    | | | | | | |____2.6.6
    | | | | | | | |____jackson-core-2.6.6.jar
    | | | | | |____jackson-databind
    | | | | | | |____2.6.6
    | | | | | | | |____jackson-databind-2.6.6.jar
    | | | | |____dataformat
    | | | | | |____jackson-dataformat-yaml
    | | | | | | |____2.6.6
    | | | | | | | |____jackson-dataformat-yaml-2.6.6.jar
    | | | | |____jaxrs
    | | | | | |____jackson-jaxrs-base
    | | | | | | |____2.6.6
    | | | | | | | |____jackson-jaxrs-base-2.6.6.jar
    | | | | | |____jackson-jaxrs-json-provider
    | | | | | | |____2.6.6
    | | | | | | | |____jackson-jaxrs-json-provider-2.6.6.jar
    | | | | |____module
    | | | | | |____jackson-module-jaxb-annotations
    | | | | | | |____2.6.6
    | | | | | | | |____jackson-module-jaxb-annotations-2.6.6.jar
    | | |____google
    | | | |____guava
    | | | | |____guava
    | | | | | |____18.0
    | | | | | | |____guava-18.0.jar
    | | | | |____example
    | | | | | |____car
    | | | | | | |____car-bo
    | | | | | | | |____1.1.0-SNAPSHOT
    | | | | | | | | |____car-bo-1.1.0-SNAPSHOT.jar
    | | | | | | |____car-dao
    | | | | | | | |____1.1.0-SNAPSHOT
    | | | | | | | | |____car-dao-1.1.0-SNAPSHOT.jar
    | | | | | | |____car-dao-minimal
    | | | | | | | |____1.1.0-SNAPSHOT
    | | | | | | | | |____car-dao-minimal-1.1.0-SNAPSHOT.jar
    | | | | | | |____car-dao-minimal-querydsl
    | | | | | | | |____1.1.0-SNAPSHOT
    | | | | | | | | |____car-dao-minimal-querydsl-1.1.0-SNAPSHOT.jar
    | | | | | | |____car-dao-querydsl
    | | | | | | | |____1.1.0-SNAPSHOT
    | | | | | | | | |____car-dao-querydsl-1.1.0-SNAPSHOT.jar
    | | | | | | |____car-doc
    | | | | | | | |____1.1.0-SNAPSHOT
    | | | | | | | | |____car-doc-1.1.0-SNAPSHOT.jar
    | | | | | | |____car-dto
    | | | | | | | |____1.1.0-SNAPSHOT
    | | | | | | | | |____car-dto-1.1.0-SNAPSHOT.jar
    | | | | | | |____car-features
    | | | | | | | |____1.1.0-SNAPSHOT
    | | | | | | | | |____car-features-1.1.0-SNAPSHOT-default.cfg
    | | | | | | |____car-kar
    | | | | | | | |____1.1.0-SNAPSHOT
    | | | | | | | | |____car-kar-1.1.0-SNAPSHOT-features.xml
    | | | | | | |____car-operation
    | | | | | | | |____1.1.0-SNAPSHOT
    | | | | | | | | |____car-operation-1.1.0-SNAPSHOT.jar
    | | | | | | |____car-operation-regular
    | | | | | | | |____1.1.0-SNAPSHOT
    | | | | | | | | |____car-operation-regular-1.1.0-SNAPSHOT.jar
    | | | | | | |____car-po
    | | | | | | | |____1.1.0-SNAPSHOT
    | | | | | | | | |____car-po-1.1.0-SNAPSHOT.jar
    | | | | | | |____car-rest
    | | | | | | | |____1.1.0-SNAPSHOT
    | | | | | | | | |____car-rest-1.1.0-SNAPSHOT.jar
    | | | | | | |____car-rest-regular
    | | | | | | | |____1.1.0-SNAPSHOT
    | | | | | | | | |____car-rest-regular-1.1.0-SNAPSHOT.jar
    | | | | | | |____car-service
    | | | | | | | |____1.1.0-SNAPSHOT
    | | | | | | | | |____car-service-1.1.0-SNAPSHOT.jar
    | | | | | | |____car-service-regular
    | | | | | | | |____1.1.0-SNAPSHOT
    | | | | | | | | |____car-service-regular-1.1.0-SNAPSHOT.jar
    | | | | | | |____car-service-regular-minimal
    | | | | | | | |____1.1.0-SNAPSHOT
    | | | | | | | | |____car-service-regular-minimal-1.1.0-SNAPSHOT.jar
    | | | | | | |____car-ui-model
    | | | | | | | |____1.1.0-SNAPSHOT
    | | | | | | | | |____car-ui-model-1.1.0-SNAPSHOT.jar
    | | | | | | |____car-ui-resource
    | | | | | | | |____1.1.0-SNAPSHOT
    | | | | | | | | |____car-ui-resource-1.1.0-SNAPSHOT.jar
    | | | | |____external
    | | | | | |____external-apache-poi
    | | | | | | |____3.13.1
    | | | | | | | |____external-apache-poi-3.13.1.jar
    | | | | |____integration
    

    and my feature definition is:

    | | | | | | |____car-kar
    | | | | | | | |____1.1.0-SNAPSHOT
    | | | | | | | | |____car-kar-1.1.0-SNAPSHOT-features.xml
    

    Which is:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <features xmlns="http://karaf.apache.org/xmlns/features/v1.3.0" name="car-kar">
        <feature name="blackbelt-car" description="Car application" version="1.1.0.SNAPSHOT">
            <configfile finalname="/deploy/hu.blackbelt.judo-car.cfg">mvn:hu.blackbelt.judo.example.car/car-features/1.1.0-SNAPSHOT/cfg/default</configfile>
            <configfile finalname="/sample-configurations/hu.blackbelt.judo-car.cfg" override="true">mvn:hu.blackbelt.judo.example.car/car-features/1.1.0-SNAPSHOT/cfg/default</configfile>
            <feature prerequisite="false" dependency="false">blackbelt-judo-repo</feature>
            <feature prerequisite="false" dependency="false">blackbelt-judo-common</feature>
            <feature prerequisite="false" dependency="false">blackbelt-judo-business</feature>
            <feature prerequisite="false" dependency="false">blackbelt-judo-rdbms</feature>
            <feature prerequisite="false" dependency="false">blackbelt-judo-integration</feature>
            <bundle start-level="95">mvn:hu.blackbelt.judo.example.car/car-bo/1.1.0-SNAPSHOT</bundle>
            <bundle start-level="95">mvn:hu.blackbelt.judo.example.car/car-po/1.1.0-SNAPSHOT</bundle>
            <bundle start-level="95">mvn:hu.blackbelt.judo.example.car/car-dao/1.1.0-SNAPSHOT</bundle>
            <bundle start-level="95">mvn:hu.blackbelt.judo.example.car/car-dao-querydsl/1.1.0-SNAPSHOT</bundle>
            <bundle start-level="95">mvn:hu.blackbelt.judo.example.car/car-dao-minimal/1.1.0-SNAPSHOT</bundle>
            <bundle start-level="95">mvn:hu.blackbelt.judo.example.car/car-dao-minimal-querydsl/1.1.0-SNAPSHOT</bundle>
            <bundle start-level="95">mvn:hu.blackbelt.judo.example.car/car-doc/1.1.0-SNAPSHOT</bundle>
            <bundle start-level="95">mvn:hu.blackbelt.judo.example.car/car-dto/1.1.0-SNAPSHOT</bundle>
            <bundle start-level="95">mvn:hu.blackbelt.judo.example.car/car-operation/1.1.0-SNAPSHOT</bundle>
            <bundle start-level="95">mvn:hu.blackbelt.judo.example.car/car-operation-regular/1.1.0-SNAPSHOT</bundle>
            <bundle start-level="95">mvn:hu.blackbelt.judo.example.car/car-rest/1.1.0-SNAPSHOT</bundle>
            <bundle start-level="95">mvn:hu.blackbelt.judo.example.car/car-rest-regular/1.1.0-SNAPSHOT</bundle>
            <bundle start-level="95">mvn:hu.blackbelt.judo.example.car/car-service/1.1.0-SNAPSHOT</bundle>
            <bundle start-level="95">mvn:hu.blackbelt.judo.example.car/car-service-regular/1.1.0-SNAPSHOT</bundle>
            <bundle start-level="95">mvn:hu.blackbelt.judo.example.car/car-service-regular-minimal/1.1.0-SNAPSHOT</bundle>
            <bundle start-level="95">mvn:hu.blackbelt.judo.example.car/car-ui-model/1.1.0-SNAPSHOT</bundle>
            <bundle start-level="95">mvn:hu.blackbelt.judo.example.car/car-ui-resource/1.1.0-SNAPSHOT</bundle>
            <bundle start-level="95">mvn:hu.blackbelt/judo-web/1.0-SNAPSHOT</bundle>
        </feature>
        <feature name="blackbelt-judo-repo" description="BlackBelt Judo: Repo" version="1.1.0.SNAPSHOT">
            <feature prerequisite="false" dependency="false">wrap</feature>
            <feature version="1.0.0" prerequisite="false" dependency="false">repo-spifly</feature>
            <feature prerequisite="false" dependency="false">pax-cdi</feature>
            <feature prerequisite="false" dependency="false">jndi</feature>
            <feature prerequisite="false" dependency="false">transaction</feature>
            <feature prerequisite="false" dependency="false">jasypt-encryption</feature>
            <feature prerequisite="false" dependency="false">eventadmin</feature>
            <feature prerequisite="false" dependency="false">scr</feature>
            <feature prerequisite="false" dependency="false">http</feature>
            <feature prerequisite="false" dependency="false">http-whiteboard</feature>
            <feature prerequisite="false" dependency="false">repo-cxf-jaxrs</feature>
            <feature prerequisite="false" dependency="false">repo-cxf-jaxws</feature>
            <feature prerequisite="false" dependency="false">repo-cxf-rs-security-cors</feature>
            <feature prerequisite="false" dependency="false">repo-cxf-rs-description-swagger2</feature>
            <feature prerequisite="false" dependency="false">repo-javassist</feature>
            <feature prerequisite="false" dependency="false">repo-jackson</feature>
            <feature prerequisite="false" dependency="false">repo-functionaljava</feature>
            <feature prerequisite="false" dependency="false">repo-commons-osgi</feature>
            <feature prerequisite="false" dependency="false">repo-commons-mime</feature>
            <feature prerequisite="false" dependency="false">repo-paranamer</feature>
            <feature prerequisite="false" dependency="false">repo-querydsl</feature>
            <feature prerequisite="false" dependency="false">repo-h2</feature>
            <feature prerequisite="false" dependency="false">repo-hsqldb</feature>
            <feature prerequisite="false" dependency="false">repo-postgresql</feature>
            <feature prerequisite="false" dependency="false">repo-oracle</feature>
            <feature prerequisite="false" dependency="false">repo-guava</feature>
            <feature prerequisite="false" dependency="false">repo-joda-time</feature>
            <feature prerequisite="false" dependency="false">repo-markup</feature>
            <feature prerequisite="false" dependency="false">repo-reflections</feature>
            <feature prerequisite="false" dependency="false">repo-javax-validation</feature>
            <feature prerequisite="false" dependency="false">repo-hibernate-validator</feature>
            <feature prerequisite="false" dependency="false">repo-concurrentlinkedhashmap-lru</feature>
            <feature prerequisite="false" dependency="false">repo-java-sizeof</feature>
            <feature prerequisite="false" dependency="false">repo-orika-core</feature>
            <feature prerequisite="false" dependency="false">repo-management</feature>
            <feature prerequisite="false" dependency="false">repo-paxjdbc</feature>
            <feature prerequisite="false" dependency="false">repo-apache-poi</feature>
            <feature prerequisite="false" dependency="false">repo-antlr4</feature>
            <feature prerequisite="false" dependency="false">repo-sling-healthcheck</feature>
            <feature prerequisite="false" dependency="false">repo-dom4j</feature>
            <feature prerequisite="false" dependency="false">repo-pdfbox</feature>
            <feature prerequisite="false" dependency="false">repo-freemarker</feature>
            <feature prerequisite="false" dependency="false">shiro-web</feature>
            <feature prerequisite="false" dependency="false">nimbus-jose-jwt</feature>
            <feature prerequisite="false" dependency="false">groovy-all</feature>
            <feature prerequisite="false" dependency="false">javax-el</feature>
            <feature prerequisite="false" dependency="false">unboundid-ldapsdk</feature>
            <feature prerequisite="false" dependency="false">javax.mail</feature>
            <feature prerequisite="false" dependency="false">org.passay</feature>
        </feature>
        <feature name="repo-apache-poi" version="3.13.0">
            <feature prerequisite="false" dependency="false">repo-bouncycastle</feature>
            <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.xmlbeans/2.6.0_2</bundle>
            <bundle>mvn:hu.blackbelt.judo.external/external-apache-poi/3.13.1</bundle>
        </feature>
        <feature name="repo-bouncycastle" version="1.55.0">
            <bundle>mvn:org.bouncycastle/bcprov-jdk15on/1.55</bundle>
            <bundle>mvn:org.bouncycastle/bcmail-jdk15on/1.55</bundle>
            <bundle>mvn:org.bouncycastle/bcpkix-jdk15on/1.55</bundle>
        </feature>
        <feature name="repo-javassist" version="3.19.0.GA">
            <bundle>mvn:org.javassist/javassist/3.19.0-GA</bundle>
        </feature>
        <feature name="repo-spifly" version="1.0.0">
            <bundle>mvn:org.ow2.asm/asm-all/4.2</bundle>
            <bundle>mvn:org.apache.aries.spifly/org.apache.aries.spifly.dynamic.bundle/1.0.0</bundle>
        </feature>
    </features>
    

    This feature file is an effective feature file which contains all feature repositories which are manifested in KAR file, which mean if there is more features on maven-karaf-plugin as feature dependency defined, all of them are aggregated here. The KAR feature bundle groupId and artifactId is the maven project of the assembly. (Which in you case can be any name)