Apache Karaf

http://karaf.apache.org/

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:

  • Hot deployment: Karaf supports hot deployment of OSGi bundles by monitoring jar files inside the [home]/deploy directory. Each time a jar is copied in this folder, it will be installed inside the runtime. You can then update or delete it and changes will be handled automatically. In addition, the Karaf also supports exploded bundles and custom deployers (blueprint and spring ones are included by default).
  • Dynamic configuration: Services are usually configured through the ConfigurationAdmin OSGi service. Such configuration can be defined in Karaf using property files inside the [home]/etc directory. These configurations are monitored and changes on the properties files will be propagated to the services.
  • Logging System: using a centralized logging back end supported by Log4J, Karaf supports a number of different APIs (JDK 1.4, JCL, SLF4J, Avalon, Tomcat, OSGi)
  • Provisioning: Provisioning of libraries or applications can be done through a number of different ways, by which they will be downloaded locally, installed and started.
  • Native OS integration: Karaf can be integrated into your own Operating System as a service so that the lifecycle will be bound to your Operating System.
  • Extensible Shell console: Karaf features a nice text console where you can manage the services, install new applications or libraries and manage their state. This shell is easily extensible by deploying new commands dynamically along with new features or applications.
  • Remote access: use any SSH client to connect to Karaf and issue commands in the console
  • Security framework based on JAAS
  • Managing instances: Karaf provides simple commands for managing multiple instances. You can easily create, delete, start and stop instances of Karaf through the console.
  • Supports the latest OSGi 4.2 containers: Apache Felix Framework 3.0 and Eclipse Equinox 3.6

 

=============

1. 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 before becoming a top level project.

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, you will still need to install some software before installing Karaf.

Karaf requires a Java SE 5 environment to run. Refer to http://www.oracle.com/technetwork/java/javase/ for details on how to download and install Java SE 1.5 or greater.

Download binaries

You will need to select the appropriate installation image for the platform you're using to run Karaf. Open a Web browser and access the following URL, there you will find the available packages for download (binaries and source code).

http://karaf.apache.org/index/community/download.html

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 <KARAF_HOME>. 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.gz 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 <KARAF_HOME>. To start the server, run the following command in Windows:

bin\karaf.bat

respectively on Unix:

bin/karaf

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

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

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:

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 <tab> cr <tab> instead of admin:create.

Deploy a sample application

While you will learn in the Karaf user's guide how to fully use and leverage Apache Karaf, let's install a sample Apache Camel application for now:

In the console, run the following commands:

features:addurl mvn:org.apache.camel/camel-example-osgi/2.7.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:

features:uninstall camel-example-osgi

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:

^D

Alternatively, you can also run the following command:

osgi:shutdown

Summary

This document showed 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.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值