Develop an OSGi application
As an introduction to developing an OSGi application, we can develop a simple HelloWorld OSGi application, which consists of two bundles. One bundle defines a hello service, and the other is a client bundle that uses this service to produce the message OSGi Service: Hello World!.
An OSGi application is a Java™ application that uses OSGi technologies. OSGi applications are collections of OSGi bundles (typically bundles that use the Blueprint component model), and can expose or consume a number of services. The OSGi application described in these topics demonstrates the use of the OSGi service registry to share the hello service between the defining bundle and the client bundle. All interactions with the service registry are handled through Blueprint.
OSGi bundles are packaged as JAR files with a .jar extension. A single OSGi application is packaged in an enterprise bundle archive (EBA) file with a .eba extension, just as an enterprise application is packaged in an EAR file with a .ear extension. In this example application, the bundles are packaged directly in the EBA file. However, the EBA file does not have to contain the bundles; they can be pulled in at run time.
The steps in the following procedure are specific to this example application, and lead you through creating the application artifacts by using IBM Rational Application Developer Version 8 or a similar tool.
What to do next
After creating the OSGi application, we can deploy the application to WebSphere Application Server by using either the administrative console or wsadmin commands; for details, see Deploy an OSGi application as a business-level application.
We might also want to explore the sample OSGi applications.
Subtopics
- Create a service bundle
For the simple HelloWorld OSGi application, the service bundle implements the HelloWorldEBA interface, and exports it as an OSGi service.
- Create a client bundle
For the simple HelloWorld OSGi application, the client bundle calls the HelloWorldService service, and uses it to produce the message OSGi Service: Hello World!.
- Create an OSGi application
For the simple HelloWorld OSGi application, the bundle that defines the service and the bundle that uses the service are packaged together in an OSGi application.
Parent topic: Develop OSGi applications
Related concepts
The Blueprint Container The WebSphere programming model and OSGi OSGi applications
Related tasks
Develop a composite bundle
Best practices for developing and working with OSGi applications
Develop enterprise OSGi applications for WebSphere Application ServerOSGi application design guidelines Writing extensible OSGi applications