Book Image

OSGi and Apache Felix 3.0 Beginner's Guide

By : Walid Joseph Gédéon
Book Image

OSGi and Apache Felix 3.0 Beginner's Guide

By: Walid Joseph Gédéon

Overview of this book

<p>The OSGi specification is a module system and service platform that implements a complete and dynamic component model. Wasn't that a complicated definition! So how would you really use it in practical modular applications? Let this book break down the seemingly overwhelming OSGi standards for you by explaining Apache Felix's powerful architecture in a simple and easy-to-understand manner using Apache Felix framework to get you up and running sooner than you could expect.<br /><br />The OSGi standards have found a wide range of applications in the context of the Enterprise, Telecommunications, Telematics, Smart Home, E-Health, and Mobile applications, to name just a few. Apache Felix is one of the most famous implementations of the OSGi framework specification. This book introduces OSGi on the simple and extensible Felix framework and guides you from the development environment setup to the troubleshooting of potential issues, walking you through the development of an OSGi-based application and explaining relevant software design concepts.<br /><br />The book starts with an introduction to the OSGi Service Platform, its parts, and its bundle structure. It then walks you through setting up the Felix framework and your development environment. It describes the Felix Framework and how to operate it using Gogo. It will teach you everything possible about the practical implementation of OSGi using the Felix Framework as a launch pad.<br /><br />The book then kicks off the Bookshelf project, a case study that will be used to progressively explain the important concepts around OSGi using the Felix framework. The Bookshelf project feature trail will set the context to explain OSGi headers, the bundle activator, the bundle context, and so on.<br /><br />As you implement the bookshelf step by step, you learn about OBR repositories, dependency management, and bundle version management with Felix.<br /><br />Moving ahead, a few more advanced topics are covered, such as using iPOJO for dependency injection and service registration; then the book moves on to the implementation of a web-based graphical interface, first using a simple Servlet, and then building a JSP-based Web Application Bundle.<br /><br />OSGi service specifications such as the Log Service, Http Service, and Web Container are explained. Finally, the book describes some of the common pitfalls during bundle development, and gives hints on troubleshooting them in Felix.</p>
Table of Contents (22 chapters)
OSGi and Apache Felix 3.0
Credits
About the Author
About the Reviewers
Preface

Appendix A. Eclipse, Maven, and Felix

Writing Java code can be fun with just a simple text editor like vi and javac to compile, at times. However, when the project grows bigger than just a few classes and starts having many dependencies, the need for an IDE, a dependency management, and a build process system become a must.

A good selection of tools that integrate well with one another improves the overall productivity while reducing the impact of human intervention in repetitive, day-to-day processes, which can be automated.

In this appendix, we will go over a short introduction to those tools. Then we'll look at a few ways to use Eclipse in the process of developing and testing Felix bundles and the Maven project setup for building and packaging them.

It is not supposed to be a complete overview of how to use Eclipse or Maven; so additional research and online reading will be required. However, it will give us some basics to help us to get going. Some of the more experienced developers will most probably just whiz through it looking for the main pointers.

In this appendix, you will learn how to:

  • Extend Eclipse with plugins that integrate it with Felix and Maven

  • Set up a new project using Eclipse and Maven

  • Configure the JVM launch options to set up a Felix framework for remote debugging

  • Configure Eclipse to connect to the standalone Felix as a remote debugger

  • Embed Felix into Eclipse

  • Debug bundles with an embedded Felix

Productivity tools

Using development tools speeds up the development cycle and reduces issues due to manual intervention in the build process. They ensure that the correct dependencies are available, the bundling contains the right descriptors, and that the bundles are deployed to the expected target with the expected name. The build process becomes a simple exercise that's automated by the selected tools.

The first two tools that a serious developer should invest time in selecting are a good IDE and a build management system.

An Integrated Development Environment

An IDE is a software application that provides developers with a set of integrated components that assist in the development activity. An IDE will provide source code and resource editors frequently with contextual assistance on parts of the content and integration with a build management system. Many also provide integration with source code management and issue tracking systems.

There are many good IDEs for free! Take a look at the following:

Or you can just Google 'Java IDE' for a wide selection of choices for IDEs and build management systems.

For this project, I've picked Eclipse as my IDE. Eclipse is an extensible application framework (OSGi-based) with a rich feature-set and plugins. If you're interested, visit the Eclipse website for more information (http://www.eclipse.org/).

A build management system

Build management systems assist in the build side of things, they help in automating many of the repetitive tasks involved such as from the compilation of source code to the deployment of the end result to a common location.

The main outcome of this automation is the ability to develop components following a continuous integration strategy, whereby the different components of a system are unit tested and integration tested as they are developed. In those setups, a close eye must be kept on the automated integration and testing units.

One well-known build system is Apache Ant (http://ant.apache.org/), which allows the description of the sequence of tasks to be performed to build a system in one or more xml files; they act as build scripts.

I've picked Maven as the dependency management and build system (http://maven.apache.org). In addition to allowing automation of the build, packaging, and deployment of bundles with little configuration, it structures the build process in lifecycles and can be extended with a rich selection of plugins (Maven is described in greater detail in Chapter 2,