Creating OSGi bundle projects

An OSGi bundle is a Java™ archive file that contains Java code, resources, and a manifest that describes the bundle and bundle 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.

Procedure

  1. Click File > New > Other > OSGi > OSGi Bundle Project and then click Next.
    The New OSGi Bundle Project wizard opens.
  2. In the Project name field, enter the name of your bundle project.
  3. Select a Target runtime from the drop-down list.
    Set the target run time to define an installed runtime environment. Run times are used at build time to compile projects
  4. In the Configuration list, you can select one or more of the following configurations:
    • Add Web support - Adds support for dynamic web page content to your bundle project.
    • Add persistence support - Adds JPA support to your bundle project.
    • Custom - Adds support to deploy your project as an OSGi bundle project so that you can add additional facets to your project. Click Advanced - Adds facets to your project.
      Important:
      You can develop the following Java EE applications as OSGi applications:
      • Web applications
      • Java Persistence API (JPA) applications
      • JAX-RS (REST) Web services
      • JavaServer Faces applications
      • XML applications
      • EJBs
    • Generate blueprint file - Creates a blueprint file and adds it to your bundle project.
  5. In the Application membership section, select Add bundle to application and then select an application project from the drop-down list or create a new application project.
  6. Follow the wizard prompts.
    Restriction: If your bundle manifest file uses the Import-Package property to declare a bundle dependency for a bundle that is not in your workspace or your target platform, the editor marks the dependency as an error. To work around this limitation, make sure that all the bundles that you declare as a dependency are in your workspace, or use the quick fix to add the bundle to the target platform. To use the quick fix, switch to the Markers view and then right-click the error marker and select Quick Fix.

Results

Your OSGi bundle project is created and your bundle manifest is added to your project.
Important: When you specify bundle dependencies in your MANIFEST.MF file, use the property Import-Package instead of Require-bundle. If you use Require-bundle to specify bundle dependencies, your application does not deploy.
Import-Package is a more flexible way to declare dependencies:
  • You can declare dependencies on the functionality that you need rather than on the bundle where the functionality originated, as it does not add unnecessary dependencies on packages that are not required by your bundle but are included in the dependent bundle.
  • You can specify versions or version ranges for the declared package, therefore you do not have to react to changes in different versions of the bundle.

What to do next

Now that you have created a bundle project, you can create your business logic, export the OSGi bundle as a JAR file, add the bundle to an OSGi application, or add the bundle to a composite bundle.