Book Image


Book Image


Overview of this book

Table of Contents (17 chapters)
Apache Karaf Cookbook
About the Authors
About the Reviewers


Welcome to Apache Karaf Cookbook. This Cookbook has been created to provide you with best practices and lessons learned from working with Apache Karaf in the trenches.

The recipes in this book are not to be read in a serial manner. Readers are expected to pick and choose recipes as per their needs. We've taken the greatest care to make sure it's possible to refer to foundational knowledge wherever applicable. However, we do expect our audience to have some background in OSGi, Karaf, and the packages each recipe focuses on. Readers requiring more background information on Karaf and OSGi might seek out the following books:

  • Learning Apache Karaf, Johan Edstrom, Jamie Goodyear, and Heath Kesler, Packt Publishing

  • Instant OSGi Starter, Johan Edstrom and Jamie Goodyear, Packt Publishing

What this book covers

Chapter 1, Apache Karaf for System Builders, covers recipes on how to make Apache Karaf more production ready. Topics such as improved logging, custom commands, branding, management, and high availability are explored.

Chapter 2, Making Smart Routers with Apache Camel, introduces Apache Camel commands, and then discusses how to build recipes for a Camel Router using Plain Old Java Objects (POJO), Blueprint, Blueprint with the Configuration Admin support, and finally, using a managed service factory.

Chapter 3, Deploying a Message Broker with Apache ActiveMQ, explores how to use Apache ActiveMQ in an embedded fashion and walks through the different commands for monitoring and interacting with the embedded ActiveMQ broker.

Chapter 4, Hosting a Web Server with Pax Web, explains how to configure and use Apache Karaf with Pax Web. It starts with basic Http Service to full web application support.

Chapter 5, Hosting Web Services with Apache CXF, shows how to set up Apache CXF endpoints in Karaf for both RESTful- and WSDL-based web services.

Chapter 6, Distributing a Clustered Container with Apache Karaf Cellar, explains the setup of Cellar and introduces the usage of its commands.

Chapter 7, Providing a Persistence Layer with Apache Aries and OpenJPA, explores adding Java persistence and transaction support to your OSGi environment.

Chapter 8, Providing a Big Data Integration Layer with Apache Cassandra, shows how to install Cassandra client bundles into Karaf, set up modeling data, and build your project to take advantage of a Cassandra-backed persistence layer.

Chapter 9, Providing a Big Data Integration Layer with Apache Hadoop, shows you how to integrate all of the Hadoop dependencies into a feature file, deploy them correctly into Karaf while managing resources, and use HDFS to store and retrieve data.

Chapter 10, Testing Apache Karaf with Pax Exam, explains how to perform integration tests with OSGi in general and shows how to use Apache Karaf in your integration test.

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 recipes included in this book:

  • Apache Karaf 3.0

  • Oracle Java SDK 1.7

  • Apache Maven 3.0

  • Git Client

  • Any text editor

Who this book is for

Apache Karaf Cookbook is a collection of recipes for developers and system administrators looking to apply best practices when developing and deploying their applications. Readers will discover many recipes that pertain to service-oriented architectures and managing Big Data, as well as several libraries that require some experience with OSGi to fully utilize their potential.


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, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We append jmxRole to the admin group."

A block of code is set as follows:


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


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

karaf@root()> feature:repo-add mvn:com.packt/features-file/1.0.0-SNAPSHOT/xml/features

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: "The QueueSize column shows the number of messages that are currently in the queue waiting to be consumed."


Warnings or important notes appear in a box like this.


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

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 If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.


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, 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


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.


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.