h1. Custom distributions As Karaf is an OSGi container, it's heavily used as an application and middleware kernel. You may wish to construct your own Karaf distribution preconfigured to your requirements. This custom distribution could contain: - branding to change the Karaf console look-and-feel - configuration files (in the etc folder) altered to your requirements - pre-packaged artifacts in the deploy folder - a pre-populated system repository (containing your own bundle and features descriptor) - renamed or specific scripts in the bin folder - system documentation files h2. Maven assembly Basically a Karaf custom distribution involves: 1. Uncompressing a standard Karaf distribution in a given directory. 2. Populating the system repo with your features. 3. Populating the lib directory with your branding or other system bundle jar files. 4. Overriding the configuration files in the etc folder. These tasks could be performed using scripting, or more easily and portable, using Apache Maven and a set of Maven plugins. For instance, the Maven POM could look like: {code} my.company mycustom-karaf 1.0 pom My Unix Custom Karaf Distribution 2.2.2 org.apache.karaf apache-karaf ${karaf.version} tar.gz org.apache.karaf apache-karaf ${karaf.version} xml features ${project.basedir}/src/main/filtered-resources true **/* org.apache.maven.plugins maven-resources-plugin filter generate-resources resources org.apache.karaf.tooling features-maven-plugin ${karaf.version} add-features-to-repo generate-resources add-features-to-repo mvn:org.apache.karaf/apache-karaf/${karaf.version}/xml/features file:${project.basedir}/target/classes/my-features.xml my-feature org.apache.maven.plugins maven-dependency-plugin copy generate-resources copy my.groupId my.branding.id 1.0 target/dependencies mybranding.jar unpack generate-resources unpack org.apache.karaf apache-karaf tar.gz target/dependencies org.apache.maven.plugins maven-assembly-plugin bin package single src/main/descriptors/bin.xml false gnu {code} The Maven POM will download the Karaf standard distribution and prepare resources to be processed by the Maven assembly plugin. Your Maven project structure should look like: * pom.xml: the previous POM file * src/main/descriptors/bin.xml: the assembly maven plugin descriptor (see below) * src/main/filtered-resources: contains all resource files that have Maven property values to be filtered/replaced. Typically, this will include features descriptor and configuration files. * src/main/distribution: contains all raw files which will be copied as-is into your custom distribution. For instance, {{src/main/filtered-resources}} could contain: * {{my-features.xml}} where maven properties will be replaced * {{etc/org.apache.karaf.features.cfg}} file containing your my-features descriptor: {code} # # 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 {code} The {{src/main/distribution}} contains all your custom Karaf configuration files and scripts, as, for examples: * etc/org.ops4j.pax.logging.cfg {code} # 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 {code} * etc/system.properties {code} # # 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} {code} * etc/users.properties {code} admin=admin,admin {code} * You can add a {{etc/custom.properties}}, it's a placeholder for any override you may need. For instance: {code} karaf.systemBundlesStartLevel=50 obr.repository.url=http://svn.apache.org/repos/asf/servicemix/smx4/obr-repo/repository.xml org.osgi.framework.system.packages.extra = \ org.apache.karaf.branding; \ com.sun.org.apache.xalan.internal.xsltc.trax; \ com.sun.org.apache.xerces.internal.dom; \ com.sun.org.apache.xerces.internal.jaxp; \ com.sun.org.apache.xerces.internal.xni; \ com.sun.jndi.ldap {code} Now, we can "assemble" our custom distribution using the Maven assembly plugin. The Maven assembly plugin uses an assembly descriptor, configured in POM above to be {{src/main/descriptors/bin.xml}}: {code} bin tar.gz target/dependencies/apache-karaf-${karaf.version} / **/demos/** bin/** etc/system.properties etc/users.properties etc/org.apache.karaf.features.cfg etc/org.ops4j.pax.logging.cfg LICENSE NOTICE README RELEASE-NOTES karaf-manual*.html karaf-manual*.pdf target/dependencies/apache-karaf-${karaf.version} / bin/admin bin/karaf bin/start bin/stop 0755 target/dependencies my-custom.jar /lib/ src/main/distribution / 0644 target/classes/etc /etc/ unix 0644 target/features-repo /system ${basedir}/target/dependencies/apache-karaf-${karaf.version}/bin/karaf /bin/ my-custom 0755 unix ${basedir}/target/classes/features.xml /system/my.groupid/my-features/${project.version} my-features-${project.version}-features.xml 0644 unix {code} To build your custom Karaf distribution, just run: {code} mvn install {code} You will find your Karaf custom distribution tar.gz in the target directory. h2. Roadmap A distribution goal is in preparation in the next Karaf h2. Custom distribution examples * [Apache ServiceMix 4|http://svn.apache.org/repos/asf/servicemix/smx4/features/trunk/assembly/] * [Apache ServiceMix NMR|http://svn.apache.org/repos/asf/servicemix/smx4/nmr/trunk/assembly/] * [BuildProcess BuildEraser|http://buildprocess.svn.sourceforge.net/viewvc/buildprocess/builderaser/trunk/assembly/]