For the simple hello-world OSGi application, the bundle that defines the service, and the bundle that uses the service, are packaged together in an OSGi application.
You can create your application as described in this topic, in which case the application manifest file is created for you by the tooling, or you can create your application using Apache Ant.
OSGi bundles are packaged as Java archive (.jar) files. A single OSGi application is packaged in an enterprise bundle archive (.eba) file, just as an enterprise application is packaged in an enterprise archive (.ear) file. 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. For an OSGi application deployed to WebSphere® Application Server, a bundle can be located in the .eba file, or in the WebSphere Application Server internal bundle repository, or in an external bundle repository. Every .eba file contains an application manifest (APPLICATION.MF) file, which contains the metadata that defines the application. It lists the bundles that the application uses, and says where each bundle is located.
IBM® Rational® Application Developer Version 8 provides graphical support for creating and packaging bundles. The sample procedure below uses this tool. You can also use other tools, and the steps are adaptable to other tools.
This sample procedure creates a simple hello-world OSGi application called , in which the two bundles Service and Client are packaged together in an .eba file.
When you deploy and start this application, it prints the greeting message "OSGi Service: Hello World!" to the system output log.
[4/15/10 14:07:33:295 GMT] 00000023 SystemOut O Client: Start... [4/15/10 14:07:33:581 GMT] 00000023 SystemOut O OSGi Service: Hello World! [4/15/10 14:07:33:581 GMT] 00000023 SystemOut O Client: End...