Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • my-features.xml where maven properties will be replaced
  • etc/org.apache.karaf.features.cfg file containing your my-features descriptor:
    Code Block
    #
    # Comma separated list of features repositories to register by default
    #
    featuresRepositories=mvn:org.apache.karaf/apache-karaf/${karaf.version}/xml/features,mvn:my.groupId/my-features/${project.version}/xml/features
    
    #
    # Comma separated list of features to install at startup
    #
    featuresBoot=config,ssh,management,my-feature
    

The src/main/distribution contain all your custom Karaf configuration files and script, as, for examples:

  • etc/org.ops4j.pax.logging.cfg
    Code Block
    
    # Root logger
    log4j.rootLogger=INFO, out, osgi:VmLogAppender
    log4j.throwableRenderer=org.apache.log4j.OsgiThrowableRenderer
    
    # CONSOLE appender not used by default
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p | %-16.16t | %-32.32C %4L | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n
    
    # File appender
    log4j.appender.out=org.apache.log4j.RollingFileAppender
    log4j.appender.out.layout=org.apache.log4j.PatternLayout
    log4j.appender.out.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p | %-16.16t | %-32.32C %4L | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n
    log4j.appender.out.file=${karaf.home}/log/my-customer-distribution.log
    log4j.appender.out.append=true
    log4j.appender.out.maxFileSize=1MB
    log4j.appender.out.maxBackupIndex=10
    
    # Sift appender
    log4j.appender.sift=org.apache.log4j.sift.MDCSiftingAppender
    log4j.appender.sift.key=bundle.name
    log4j.appender.sift.default=my-custom
    log4j.appender.sift.appender=org.apache.log4j.FileAppender
    log4j.appender.sift.appender.layout=org.apache.log4j.PatternLayout
    log4j.appender.sift.appender.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p | %-16.16t | %-32.32c{1} | %-32.32C %4L | %m%n
    log4j.appender.sift.appender.file=${karaf.data}/log/$\\{bundle.name\\}.log
    log4j.appender.sift.appender.append=true
    
  • etc/system.properties
    Code Block
    
    #
    # The properties defined in this file will be made available through system
    # properties at the very beginning of the FAS boot process.
    #
    
    # Log level when the pax-logging service is not available
    # This level will only be used while the pax-logging service bundle
    # is not fully available.
    # To change log levels, please refer to the org.ops4j.pax.logging.cfg file
    # instead.
    org.ops4j.pax.logging.DefaultServiceLog.level=ERROR
    
    #
    # Name of this custom instance.
    #
    karaf.name=my-custom
    
    #
    # Default repository where bundles will be loaded from before using
    # other maven repositories. For the full maven configuration, see the
    # org.ops4j.pax.url.mvn.cfg file.
    #
    karaf.default.repository=system
    
    #
    # Location of a shell script that will be run when starting a shell
    # session. This script can be used to create aliases and define
    # additional commands.
    #
    karaf.shell.init.script=${karaf.home}/etc/shell.init.script
    
    #
    # Set this empty property to avoid errors when validating xml documents.
    #
    xml.catalog.files=
    
    #
    # Suppress the bell in the console when hitting backspace to many times
    # for example
    #
    jline.nobell=true
    
    #
    # Default port for the OSGi HTTP Service
    #
    org.osgi.service.http.port=8181
    
    #
    # Allow usage of ${custom.home} as an alias for ${karaf.home}
    #
    custom.home=${karaf.home}
    
  • etc/users.properties
    Code Block
    
    admin=admin,admin
    

Now, we can "assemble" our custom distribution using the Maven assembly plugin. The Maven assembly plugin uses an assembly descriptor in the src/main/descriptors/bin.xml:

Code Block

<assembly>

    <id>bin</id>

    <formats>
        <format>tar.gz</format>
    </formats>

    <fileSets>

        <!-- Expanded Karaf Standard Distribution -->
        <fileSet>
            <directory>target/dependencies/apache-karaf-${karaf.version}</directory>
            <outputDirectory>/</outputDirectory>
            <excludes>
                <exclude>**/demos/**</exclude>
                <exclude>bin/**</exclude>
                <exclude>etc/system.properties</exclude>
                <exclude>etc/users.properties</exclude>
                <exclude>etc/org.apache.karaf.features.cfg</exclude>
                <exclude>etc/org.ops4j.pax.logging.cfg</exclude>
                <exclude>LICENSE</exclude>
                <exclude>NOTICE</exclude>
                <exclude>README</exclude>
                <exclude>RELEASE-NOTES</exclude>
                <exclude>karaf-manual*.html</exclude>
                <exclude>karaf-manual*.pdf</exclude>
            </excludes>
        </fileSet>

        <!-- Copy over bin/* separately to get the correct file mode -->
        <fileSet>
            <directory>target/dependencies/apache-karaf-${karaf.version}</directory>
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>bin/admin</include>
                <include>bin/karaf</include>
                <include>bin/start</include>
                <include>bin/stop</include>
            </includes>
            <fileMode>0755</fileMode>
        </fileSet>

        <!-- Copy over jar files -->
        <fileSet>
            <directory>target/dependencies</directory>
            <includes>
                <include>my-custom.jar</include>
            </includes>
            <outputDirectory>/lib/</outputDirectory>
        </fileSet>

        <fileSet>
            <directory>src/main/distribution</directory>
            <outputDirectory>/</outputDirectory>
            <fileMode>0644</fileMode>
        </fileSet>
        <fileSet>
            <directory>target/classes/etc</directory>
            <outputDirectory>/etc/</outputDirectory>
            <lineEnding>unix</lineEnding>
            <fileMode>0644</fileMode>
        </fileSet>

        <fileSet>
            <directory>target/features-repo</directory>
            <outputDirectory>/system</outputDirectory>
        </fileSet>

    </fileSets>

    <files>
        <file>
            <source>${basedir}/target/dependencies/apache-karaf-${karaf.version}/bin/karaf</source>
            <outputDirectory>/bin/</outputDirectory>
            <destName>my-custom</destName>
            <fileMode>0755</fileMode>
            <lineEnding>unix</lineEnding>
        </file>
        <file>
            <source>${basedir}/target/classes/features.xml</source>
            <outputDirectory>/system/my.groupid/my-features/${project.version}</outputDirectory>
            <destName>my-features-${project.version}-features.xml</destName>
            <fileMode>0644</fileMode>
            <lineEnding>unix</lineEnding>
        </file>
    </files>

</assembly>

To build you custom Karaf distribution, just do:

Code Block

mvn install

You will find your Karaf custom distribution tar.gz in the target directory.TODO Complete

Roadmap

A distribution goal is in preparation in the next Karaf

...