Develop a simple OSGi application
This tutorial demonstrates how to create an OSGi application and run it on either WebSphere® Application Server traditional or Liberty. The OSGi application consists of an OSGi web bundle that contains a servlet that accesses a service that is provided in another bundle project. This tutorial is an introduction to using OSGi application development tools.
Learning objectives
In this tutorial, the following learning objectives are met:- Create an OSGi bundle and an OSGi application.
- Create and configure an OSGi blueprint configuration file.
- Configure component dependencies.
- Add dependency injection within a bundle.
- Add dependency injection between bundles.
- Deploy an OSGi application to a server.
Time required
This tutorial takes approximately 90 minutes to finish. If you explore other concepts that are related to this tutorial, it might take longer to complete.- Introduction: Develop a simple OSGi application
This tutorial demonstrates how to create an OSGi application and run it on either WebSphere Application Server traditional or Liberty. The OSGi application consists of an OSGi web bundle that contains a servlet that accesses a service that is provided in another bundle project. This tutorial is an introduction to using OSGi application development tools. - Lesson 1: Create the bundle and application
An OSGi bundle is a Java™ archive file that contains Java code, resources, and a manifest that describes the bundle and its dependencies. An OSGi bundle contains the business logic and metadata that you need to run a service. A bundle is a module in an application, which in turn is deployed to a server. - Lesson 2: Develop the business logic
- Lesson 3: Create the blueprint configuration file
The blueprint configuration file contains the component assembly and configuration information for a bundle. The file describes how components are registered in the OSGi service registry or how they look up services from the OSGi service registry. This information is used at run time to instantiate and configure the required components when the bundle is started. In this tutorial, the blueprint file defines a service that other components can use to access the counter that is defined in Lesson 2. - Lesson 4: Create a servlet that accesses an OSGi service
- Lesson 5: Deploy the OSGi Counter application
Follow these steps to deploy the application to a WebSphere Application Server installation that has the OSGi feature pack installed. Refer to the WebSphere Application Server documentation for installation and configuration details. - Lesson 6: Add dependency injection within a bundle
Dependency injection allows one bean to access another bean without having to implement any code to create the bean instance. The required bean instance is created by the blueprint container by using information that is contained in the blueprint configuration file. - Lesson 7: Add dependency injection between bundles
In the previous lesson, you learned how to use dependency injection within a bundle. Dependency injection between bundles requires an extra reference entry in the blueprint configuration file. - Summary
You created an OSGi application that consists of an OSGi web bundle. The OSGi web bundle contains a servlet that accesses a service that is provided in another bundle project.