The Maven Cookbook

Chapter 1. Cooking with Maven and OSGi

Chapter 1. Cooking with Maven and OSGi

1.1. Introduction

OSGi is a stable, widely used framework for developing and deploying component-based systems. If you've been using Eclipse, you've already been using an OSGi container for a few years, and the pluggable and configurable nature of the Eclipse platform is a product of the OSGi standards. As a concept and as an approach, OSGi is a proven standard with an installed user base of millions and growing. It might feel like an emerging standard because solid tool support is just now emerging. Prior to the last year, you might have encountered OSGi "builds", but they were usually experienced via an IDE (such as Eclipse).

Many are starting to view OSGi as the perfect solution both for deploying server-side applications and client-side GUI applications. If you need a GUI front-end or a web application to interface with a database back-end, there is a rich array of standard components to choose from in the OSGi community. Before OSGi-based servers, if you wanted a full fledged application server with a Transaction provider and JMS integration, you had to either run some large, monolithic application server like WebSphere, or you had to hack some custom components to a lightweight servlet-container such as Apache Tomcat or Jetty. Today, you wouldn't install Jetty from scratch, you will install it as an OSGi bundle in an OSGi container such as Apache Felix. If you needed an embedded database like Apache Derby or a transaction provider, you can now tell your container what bundles to deploy and every component is developed to operate in a standard operating environment. Once you've figured out how to instantiate an empty OSGi container such as Apache Felix there is no simpler deployment mechanism for your application, and once you've connected it to Nexus Professional, you've instantly solved the deployment problem in Java. This chapter takes you through the steps required to start using Maven and OSGi together and how to use Nexus Professional to support the distribution and deployment opportunities that are possible with an OSGi bundle repository (OBR).

In this chapter, we introduce some tools and techniques you can use to start developing OSGi components (or bundles) using Maven. The following recipes focus on the intersection of Apache Felix, the OPS4J project, and the Nexus repository manager as a bridge between Maven repositories and OSGi Bundle repositories. At the end of this chapter, you should have a clear picture of how to start developing OSGi-based applications using Maven.