1. Overview

Apache Karaf is a small OSGi based runtime which provides a lightweight container onto which various components and applications can be deployed.

Here is a short list of features supported by the Karaf:

2. Quick start

If you are in a hurry to have Apache Karaf up and running right away, this section will provide you with some basic steps for downloading, building (when needed) and running the server in no time. This is clearly not a complete guide so you may want to check other sections of this guide for further information.

All you need is 5 to 10 minutes and to follow these basic steps.

Background

Apache Karaf is a small and lightweight OSGi based runtime. This provides a small lightweight container onto which various bundles can be deployed.

Apache Karaf started life as the Apache ServiceMix kernel and then moved as a Apache Felix subproject.
Don't be surprised by any transitional references which remain.

Getting the software

At this time you have one option to get the software. The fastest and easiest way is to get the binary directly from the Apache site. Since this article is intended to help you to have Apache Karaf up and running in the fastest way only the binary download will be covered at this time.

Prerequisites

Although this installation path is the fastest one, still you will need to install some software before installing Karaf.

Karaf requires a Java 5 environment to run. Refer to http://java.sun.com for details on how to download and install J2SE 1.5 or greater.

Download binaries

Depending on the platform you plan to install and run Karaf you will select the appropriate installation image. Open a Web browser and access the following URL, there you will find the available packages for download (binaries and source code).

Select the file compression format compatible with your system (zip for windows, tar.gz for unixes) by clicking directly on the link, download it and expand the binary to your hard drive in a new directory; for example in z:\karaf - from now on this directory will be referenced as . Please remember the restrictions concerning illegal characters in Java paths, e.g. !, % etc.

The installation of Karaf is as simple as uncompressing the .zip or .tar files. The next step is to start the server.

Start the server

With Karaf already installed, open a command line console and change directory to . To start the server, run the following command in Windows:

respectively on Unix:

You should see the following informations on the command line console:

You can now run your first command. Simply type the key in the console.

solid karaf@root> admin:change-port admin:connect admin:create admin:destroy admin:list admin:start admin:stop config:cancel config:edit config:list config:propappend config:propdel config:proplist config:propset config:update dev:dynamic-import dev:framework dev:print-stack-traces dev:show-tree features:addUrl features:info features:install features:list features:listUrl features:refreshUrl features:removeUrl features:uninstall log:display log:display-exception log:get log:set osgi:bundle-level osgi:headers osgi:install osgi:list osgi:ls osgi:refresh osgi:resolve osgi:restart osgi:shutdown osgi:start osgi:start-level osgi:stop osgi:uninstall osgi:update packages:exports packages:imports shell:cat shell:clear shell:each shell:echo shell:exec shell:grep shell:history shell:if shell:info shell:java shell:logout shell:new shell:printf shell:sleep shell:sort shell:tac ssh:ssh ssh:sshd cat clear each echo exec grep history if info java logout new printf sleep sort tac bundle-level headers install list ls refresh resolve restart shutdown start start-level stop uninstall update karaf@root>

You can then grab more specific help for a given command using the --help option for this command:

solid karaf@root> admin:create --help DESCRIPTION admin:create Create a new instance. SYNTAX admin:create [options] name ARGUMENTS name The name of the new container instance OPTIONS --help Display this help message -f, --feature Initial features. This option can be specified multiple times to enable multiple initial features -p, --port Port number for remote shell connection -l, --location Location of the new container instance in the file system -furl, --featureURL Additional feature descriptor URLs. This option can be specified multiple times to add multiple URLs karaf@root>

Note that the console supports tab completion, so you just need to enter ad cr instead of admin:create .
#top

Deploy a sample application

While you will learn in the remainder of this guide how to use and leverage Apache Karaf, we will just use the pre-built packaging for now.

In the console, run the following commands:

features:addurl mvn:org.apache.camel/camel-example-osgi/2.5.0/xml/features features:install camel-example-osgi

The example installed is using Camel to start a timer every 2 seconds and output a message on the console. The previous commands download the Camel features descriptor and install the example feature.

>>>> SpringDSL set body: Fri Jan 07 11:59:51 CET 2011 >>>> SpringDSL set body: Fri Jan 07 11:59:53 CET 2011 >>>> SpringDSL set body: Fri Jan 07 11:59:55 CET 2011

Stopping and uninstalling the sample application

To stop this demo, run the following command:

Common Problems

  1. Launching Karaf can result in a deadlock in Felix during module dependency resolution. This is often a result of sending a SIGINT (control-C) to the process when it will not cleanly exit. This can corrupt the caches and cause startup problems in the very next launch. It is fixed by emptying the component cache: rm -rf data/cache/*

Stopping Karaf

To stop Karaf from the console, enter ^D in the console:

Alternatively, you can also run the following command:

Summary

This document showed you how simple it is to have Apache Karaf up and running. The overall time for getting the server running should be less than five minutes if you have the prerequisite (Java 1.5) already installed. Additionally, this article also showed you how to deploy and test a simple Apache Camel application in less than five minutes.

2.1. Quick Start (Source)

If you are in a hurry to have Apache Karaf up and running right away, this section will provide you with some basic steps for checking out, building and running the server in no time. This is clearly not a complete guide so you may want to check other sections of this guide for further information.

All you need is 15 minutes and to follow these basic steps.

Background

Apache Karaf is a small and lightweight OSGi based runtime. This provides a small lightweight container onto which various bundles can be deployed.

Apache Felix Karaf started life as the Apache ServiceMix kernel and then moved as a Apache Felix subproject.
Don't be surprised by any transitional references which remain.

Getting the software

This document describes how to build the server from the latest Karaf source.

Prerequisites

Although this installation path is the fastest one, still you will need to install some software before installing Karaf.

Karaf requires a Java 5 environment to run. Refer to http://java.sun.com for details on how to download and install J2SE 1.5 or greater.

Subversion is required to checkout the source.

Maven 2 is required to build Karaf.

Checkout Source

The Karaf source is found at http://svn.apache.org/repos/asf/karaf/trunk/. To check out with a command line client:

solid $ svn co http://svn.apache.org/repos/asf/karaf/trunk/

Build

Change directory to the top level of the source checkout. Build Karaf using Maven as follows:

solid $ mvn -Pfastinstall

Distributions will be created in assembly/target. Select the file compression format compatible with your system (apache-karaf-2.0.0.zip for windows, apache-karaf-2.0.0.tar.gz for unixes) and expand the binary in a new directory; for example in z:\karaf - from now on this directory will be referenced as . Please remember the restrictions concerning illegal characters in Java paths, e.g. !, % etc.

The installation of Karaf is as simple as uncompressing the .zip or .tar files. The next step is to start the server.

To generate Eclipse projects for all modules, in KARAF_HOME type:

Then add each module location, prefixing each name with org.apache.karaf (for example org.apache.karaf.shell.core)

Start the server

With Karaf already installed, open a command line console and change directory to . To start the server, run the following command in Windows:

respectively on Unix:

You should see the following informations on the command line console:

You can now run your first command. Simply type the key in the console.

solid karaf@root> admin:change-port admin:connect admin:create admin:destroy admin:list admin:start admin:stop config:cancel config:edit config:list config:propappend config:propdel config:proplist config:propset config:update dev:dynamic-import dev:framework dev:print-stack-traces dev:show-tree features:addUrl features:info features:install features:list features:listUrl features:refreshUrl features:removeUrl features:uninstall log:display log:display-exception log:get log:set osgi:bundle-level osgi:headers osgi:install osgi:list osgi:ls osgi:refresh osgi:resolve osgi:restart osgi:shutdown osgi:start osgi:start-level osgi:stop osgi:uninstall osgi:update packages:exports packages:imports shell:cat shell:clear shell:each shell:echo shell:exec shell:grep shell:history shell:if shell:info shell:java shell:logout shell:new shell:printf shell:sleep shell:sort shell:tac ssh:ssh ssh:sshd cat clear each echo exec grep history if info java logout new printf sleep sort tac bundle-level headers install list ls refresh resolve restart shutdown start start-level stop uninstall update karaf@root>

Deploy a sample application

While you will learn in the remainder of this guide how to use and leverage Apache Felix Karaf, we will just use the pre-built packaging for now.

In the console, run the following commands:

features:install spring-dm osgi:install -s mvn:org.apache.geronimo.specs/geronimo-activation_1.1_spec/1.0.2 osgi:install -s mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.stax-api-1.0/1.1.0 osgi:install -s mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.jaxb-api-2.1/1.1.0 osgi:install -s mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.jaxb-impl/2.1.6_1 osgi:install -s mvn:org.apache.camel/camel-core/1.4.0 osgi:install -s mvn:org.springframework/spring-tx/2.5.6.SEC01 osgi:install -s mvn:org.apache.camel/camel-spring/1.4.0 osgi:install -s mvn:org.apache.camel/camel-osgi/1.4.0 osgi:install -s mvn:org.apache.camel/camel-example-osgi/1.4.0

This commands will download, install and start the specified jars.

The example installed is using Camel to start a timer every 2 seconds and output a message on the console.

>>>> MyTransform set body: Wed Jan 02 23:34:19 CET 2010 >>>> MyTransform set body: Wed Jan 02 23:34:21 CET 2010

Stopping and uninstalling the sample application

To stop this demo, run the following command:

osgi:list | grep example

In the output, locate the line containing camel-example-osgi and note the id of the bundle in the first column. Then launch the following command:

If you wish, you can start again the sample by using the following command:

To uninstall the demo, run the following command:

Common Problems

  1. Launching SMX4 can result in a deadlock in Felix during module dependency resolution. This is often a result of sending a SIGINT (control-C) to the process when it will not cleanly exit. This can corrupt the caches and cause startup problems in the very next launch. It is fixed by emptying the component cache: rm -rf data/cache/*

Stopping Karaf

To stop Karaf from the console, enter ^D in the console:

Alternatively, you can also run the following command:

Summary

This document showed you how simple it is to have Apache Karaf up and running. The overall time for getting the server running should be less than five minutes if you have the prerequisite (Java 1.5) already installed. Additionally, this article also showed you how to deploy and test a simple Apache Camel application in less than five minutes.

3. Installation

This document describes how to install and configure Apache Karaf for both Unix and Windows' platforms.
Here you will find information about what are pre requisite software, where to download Karaf from and how to customize the installation to use custom ports other than the defaults.

This article contains the following sections:

Pre-Installation Requirements

Hardware:

Operating Systems:

Environment:

Installation Procedure for Windows

This section of the Getting Started guide explains how to install binary and source distributions of Karaf on a Windows system.

In case you have to install Karaf into a very deep path or a path containing illegal characters for Java paths, e.g. !, % etc., you may add a bat file to start -> startup that executes

subst S: "C:\your very % problematic path!\KARAF"

so your Karaf root directory is S: — which works for sure and is short to type.

Windows Binary Installation

This procedure explains how to download and install the binary distribution on a Windows system.

  1. From a browser, navigate to http://karaf.apache.org/download.html.
  2. Scroll down to the "Apache Karaf" section and select the desired distribution.
    For a binary distribution, the filename will be similar to: apache-karaf-x.y.zip .
  3. Extract the files from the ZIP file into a directory of your choice. Please remember the restrictions concerning illegal characters in Java paths, e.g. !, % etc.
  4. Proceed to the #Starting Karaf section of this document.
  5. Following start-up, go to the #Testing the Installation section of this document.
  6. Optional: see 7.1. Enabling Colorized Console Output On Windows

Windows Source Installation

This procedure explains how to download and install the source distribution on a Windows system. NOTE: Karaf requires Java 5 is compile, build and run.

  1. From a browser, navigate to http://karaf.apache.org/download.html.
  2. Scroll down to the "Apache Karaf" section and select the desired distribution.
    For a source distribution, the filename will be similar to: apache-karaf-x.y-src.zip .
  3. Extract Karaf from the ZIP file into a directory of your choice. Please remember the restrictions concerning illegal characters in Java paths, e.g. !, % etc.
  4. Windows Source Installation Build Karaf using Maven 2.0.9 or greater and Java 5.
    The recommended method of building Karaf is the following: cd [karaf_install_dir]\\src where [karaf_install_dir] is the directory in which Karaf was installed. mvn Both steps take around 10 to 15 minutes.
  5. Unzip the distribution using your favorite zip tool. The windows distribution is available at \[karaf_install_dir\]\assembly\target\apache-karaf-x.y.zip
  6. Proceed to the #Starting Karaf section of this document.
  7. Following start-up, go to the #Testing the Installation section of this document.
  8. Optional: see 7.1. Enabling Colorized Console Output On Windows

Installation Procedure For Unix

Unix Binary Installation

This procedure explains how to download and install the binary distribution on a Unix system.

  1. From a browser, navigate to http://karaf.apache.org/download.html.
  2. Scroll down to the "Apache Karaf" section and select the desired distribution.
    For a binary Unix distribution, the filename will be similar to: apache-karaf-x.y.tar.gz.
  3. Extract the files from the gzip file into a directory of your choice. For example: gunzip apache-karaf-x.y.tar.gz tar xvf apache-karaf-x.y.tar Please remember the restrictions concerning illegal characters in Java paths, e.g. !, % etc.
  4. Proceed to the #Starting Karaf section of this document.
  5. Following start-up, go to the #Testing the Installation section.

Unix Source Installation

This procedure explains how to download and install the source distribution on a Unix system. This procedure assumes the Unix machine has a browser. Please see the previous #Unix Binary Installation section for ideas on how to install Karaf without a browser. NOTE: Karaf requires Java 5 to compile, build and run.

  1. From a browser, navigate to http://karaf.apache.org/download.html.
  2. Scroll down to the "Apache Karaf" section and select the desired distribution.
    For a source distribution, the filename will be similar to: apache-karaf-x.y-src.tar.gz .
  3. Extract the files from the ZIP file into a directory of your choice. For example: gunzip apache-karaf-x.y-src.tar.gz tar xvf apache-karaf-x.y-src.tar Please remember the restrictions concerning illegal characters in Java paths, e.g. !, % etc.
  4. Build Karaf using Maven 2.0.8 or greater and Java 5: The preferred method of building Karaf is the following: cd [karaf_install_dir]/src where [karaf_install_dir] is the directory in which Karaf was installed. mvn
  5. Uncompress the distribution that has just been created cd [karaf_install_dir]/assembly/target gunzip apache-karaf-x.y.tar.gz tar xvf apache-karaf-x.y.tar
  6. Proceed to the #Starting Karaf section of this document.
  7. Following start-up, go to the #Testing the Installation section.

Starting Karaf

On Windows

From a console window, change to the installation directory and run Karaf . For the binary distribution, go to

and for the source distribution go to the target directory, for example:

where karaf_install_dir is the directory in which Karaf was installed, e.g., c:\Program Files\apache-karaf-x.y .

Note: Working directories get created relative to the current directory. For the working directories to be created in the proper place, Karaf must be launched from its home/installation directory.

It will start a Karaf console, allowing you to administrate your Karaf instance.

You can launch Karaf in server mode (without terminal output):

On Unix

From a command shell, change to the installation directory and run Karaf . For the binary distribution, go to

and for the source distribution go to the target directory, for example:

where karaf_install_dir is the directory in which Karaf was installed, e.g., /usr/local/apache-karaf-x.y .

Do NOT close the console or shell in which Karaf was started, as that will terminate Karaf (unless Karaf was started with nohup).

Testing the Installation and connecting to a running Karaf

If Karaf is up and running without problems, the Window's console window or the Unix command shell will display something similar to the following log line:

You can use the client mode to connect to a running Karaf:
On Windows:

Stopping Karaf

For both Windows and Unix installations, you can perform a clean shutdown of Karaf by using the following command:

You can use the stop script too:
On Windows: