Book Image

Learning Apache Karaf

By : Jamie Goodyear, Johan Edstrom, Heath Kesler
Book Image

Learning Apache Karaf

By: Jamie Goodyear, Johan Edstrom, Heath Kesler

Overview of this book

<p>Apache Karaf is more than just an OSGi-based runtime container; it’s an ecosystem of open source technologies that makes operating and managing applications easier. 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, Karaf also supports exploded bundles and custom deployers.</p> <p>Learning Apache Karaf will introduce developers and administrators alike to the OSGi-based container, and impart best practices by example. The book shows you how to set up an Apache Karaf distribution, and how to arrive at a production-ready deployment. Learning Apache Karaf teaches you everything you need to install, configure, and administer Apache Karaf.</p> <p>Learning Apache Karaf will help guide you through the complexity of an OSGi container using sample code and configuration snippets to demonstrate the important aspects of managing and running a Karaf instance.</p> <p>Learning to install and command the runtime is just the beginning; deploying and provisioning applications is just as important to the successful implementation of a stable and scalable architecture. You will discover how to monitor runtime environments using remote access, logging, and JMX, and you will also develop production-level architectures with high availability and security.</p>
Table of Contents (16 chapters)

Preface

Welcome to Learning Apache Karaf. This book has been created especially to provide you with all the information that you'll need to get up and running with the Karaf runtime. You will learn the basics, get started with building your first applications for deployment, and discover some tips and tricks that help expose the versatility and power of the platform. Along the way, we'll also present the best practices that we have developed over years of working with Karaf.

Before we dive into exploring Karaf, let's answer one of the most often asked questions: why the name "Karaf"?

Apache Karaf originally started as a subproject of Apache ServiceMix, where it went by the name "Kernel." It provided a basic command-line interface to manage an OSGi container. Given time, the project matured until it was moved to the Apache Felix community. At this time the project was renamed "Karaf," based upon a reflection of the project's nature:

"A carafe is a small container used for serving wine and other drinks. In similarity to the name the Kernel allows applications to be more easily handled, and improves their characteristics (much like a bottle of wine left to breathe in a decanter)."

So why the respelling? It was felt that "Karaf" would be an easier search target, and it would fill the relatively empty "K" project name listings at Apache, should it ever go top level (which it did in mid 2010). Now that we have answered this most common question, let us explore Karaf.

What this book covers

Chapter 1, Installing Apache Karaf, provides a quick installation reference for users new to Apache Karaf.

Chapter 2, Commanding the Runtime, starts with an under-the-hood discussion of how Apache Karaf commands work. We then dive into a review of the most commonly used commands and ways to access them.

Chapter 3, System Configuration and Tuning, describes an Apache Karaf installation containing several default configuration options that most users will want to alter. This chapter dives into the contents of the Apache Karaf's etc folder.

Chapter 4, Provisioning, explains how the applications go about gathering all of the artifacts required for runtime, before we can begin deploying them into Apache Karaf. Apache Maven repositories and feature descriptors are introduced and explained.

Chapter 5, Deploying Applications, discusses how to deploy various application assemblies into Apache Karaf. We touch upon OSGi and non-OSGi JARs, feature descriptors, WARs, and other formats.

Chapter 6, Deploying Production-grade Apache Karaf, discusses production deployment concepts for Apache Karaf, including offline repositories, improving application logging, high availability / failover, and basic security configuration.

Chapter 7, Apache Karaf Cellar, forms our primer for Apache Karaf's clustering solution.

Chapter 8, Our Final Programming Project, helps us bring together our learned concepts to build a sample application following the best practices, now that we've studied Karaf.

Appendix, Apache Karaf Commands, provides a quick reference for the core Apache Karaf commands.

What you need for this book

The authors have taken great care to keep the quantity of software required to explore Apache Karaf to a minimum. You will need to obtain the following before trying out the samples included in this text:

  • Apache Karaf 2.3.2 or newer distribution

  • Oracle Java SDK 1.6 or newer

  • Apache Maven 3.0

  • Git Client

  • Text editor

Who this book is for

Learning Apache Karaf is for developers and system administrators who need to discover and understand how to use Apache Karaf as an operating environment in the best possible way. Developers will learn the best practices for designing applications that fully integrate into the system, while administrators gain operational experience.

Conventions

In this book you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "We can include other contexts through the use of the include directive."

A block of code is set as follows:

package com.your.organization;
import org.apache.felix.gogo.commands.Command;
import org.apache.karaf.shell.console.OsgiCommandSupport;

@Command(scope = "LAK", name = "commandname", description = "This is a sample custom command.")
public class CommandName extends OsgiCommandSupport {
    protected Object doExecute() throws Exception {
        System.out.println("Executing command commandname");
        return null;
    }
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns=http://www.osgi.org/xmlns/blueprint/v1.0.0
         Xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0">

<command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.0.0">
    <command name="LAK/commandname">
        <action class="com.your.organization.CommandName">
        </action>
        <completers>
            <ref component-id="ourCommandCompleter" />
            <null />
        </completers>
    </command>
</command-bundle>
<bean id="ourCommandCompleter" class="com.your.organization.CommandCompleter" />
</blueprint>

Any command-line input or output is written as follows:

@echo off
REM execute setup.bat to setup environment variables.
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_31
set MAVEN_HOME=c:\x1\apache-maven-3.0.4
set PATH=%JAVA_HOME%\bin;%MAVEN_HOME%\bin;%PATH%echo %PATH%

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "clicking the Next button moves you to the next screen."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.