Depending on a JAR file without including it in an OSGi application

About this task

If you want to use independently developed JAR files with an OSGi application, but you do not want to include them directly as bundles added to the application, you can configure your workspace and server to use external JAR files. You might take this approach if you want to use JAR files that have packages, but you want to keep the JAR files separate. For instance, you might want to make your application more light-weight or keep external assets separate. JAR files that you want your application to depend on must be in OSGi bundle format. Perform the following steps to ensure that the JAR file is in bundle format and to configure your workspace and server for an application to depend on a JAR file.

Procedure

  1. Create an OSGi bundle from the JAR file. If the JAR file is not already an OSGi bundle, create a bundle that is based on the JAR file. For details on how to create an OSGi bundle, see Creating an OSGi bundle from a JAR file. If you are unsure whether a JAR file is already a bundle, open up the JAR file and ensure that there is a META-INF/MANIFEST.MF file in the JAR file that contains a Bundle-SymbolicName header with the name of the bundle.
  2. Create a directory on your file system for the JAR file. In the following steps, you configure the location of the JAR archive file for the target platform information in your workspace and the internal bundle repository information on your server. Create a directory for the JAR file and make note of the location.
  3. Export or copy the bundle to the directory you created in the previous step. If the JAR file was already in bundle format on your file system, copy it to the directory you created. To convert the JAR file to bundle format, you now have a new bundle in your workspace that you can export. To export the bundle from the workspace, right-click the bundle and select Export > OSGi Bundle or Fragment. In the export dialog, click Browse to select the location to export the bundle to. Ensure that the field To JAR file has the name and location that you want. Click Finish. The bundle is exported.
  4. Edit your workspace target platform definition to include the bundle. By adding the bundle to your target platform definition, applications that depend on the bundle can compile successfully.
    1. Access Target Platform preferences. Click Window > Preferences > Plug-in Development > Target Platform.
    2. In the Target definitions section, choose the target platform that you want to compile your application against. For example, choose WebSphere Application Server v8.0. Click Edit. The Target Content dialog opens.
    3. On the Locations tab, click Add. In the Add Content dialog, click Directory. Click Next. In the Add Directory dialog, browse to the directory on your file system where the bundle is located. Click Next. Your bundle should be in the Plug-ins list.
    4. Click Finish to exit the Add Directory dialog. Click Finish again to exit the Target Content dialog. Click OK to exit the Target Platform preferences. Your workspace is now configured to compile applications that rely on packages in the bundle.
  5. Add the bundle to the server. By adding the bundle to the server, you are ensuring that the server can find the packages that your OSGi application runs after it is deployed.
    Note: This step is for WebSphere® Application Server users. If you are using a different application server, see your server documentation for how to add bundles to the server.
    From the Servers view, right-click your server and select Administration > Run Administative Console. In the administrative console, browse to Environment > OSGi bundle repositories > Internal bundle repository. Click New. In the Path to bundle section, select Local file system. Click Browse and browse to the bundle on your file system. Click OK to exit the Internal bundle repository dialog. Click the Save link. The bundle is added to the internal bundle repository and the changes on the server are saved. An OSGi application that depends on the bundle can now resolve the packages on the server after the application is deployed.
Icon that indicates the type of topic Task topic
Timestamp icon Last updated: July 17, 2017 21:58

File name: tdepjar.html