Book Image

Apache Karaf Cookbook

By : Jamie Goodyear, Johan Edstorm, Achim Nierbeck, Heath J Kesler
Book Image

Apache Karaf Cookbook

By: Jamie Goodyear, Johan Edstorm, Achim Nierbeck, Heath J Kesler

Overview of this book

Table of Contents (17 chapters)
Apache Karaf Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a CDI web application with Apache Karaf


Nowadays, modern web applications use Contexts and Dependency Injection (CDI) to wire the application. In the context of OSGi, it would be nice to have this working together with OSGi services. Pax Web, together with Pax CDI, takes care of this scenario.

Getting ready

Besides the installation of the WAR feature, it is required to install Pax CDI. Use the following commands to install them:

feature:install war
feature:install pax-cdi-web-openwebbeans

Alternatively, you can use the weld command as follows:

feature:install pax-cdi-web-weld

The source code for this recipe can be found at https://github.com/jgoodyear/ApacheKarafCookbook/tree/master/chapter4/chapter4-recipe10.

This recipe needs the bundle and web submodules. The bundle submodule contains the OSGi service, and the web submodule contains the CDI web application.

How to do it…

Let's start with the web application. The web.xml file can either be empty or can contain the entry for a welcome...