Any libraries that are required by the Java handler classes
must be placed so that references to the library from the Java handler
class can be resolved. The Java handler project is a specialized form
of OSGi bundle project, and follows the standard conventions for classpath
resolution for OSGi bundles.
About this task
To resolve references from the Java handler to the library,
the library must either
- be added to the handler project itself or
- be added to another OSGi bundle project, and a dependency must
be declared between the two OSGi bundles.
Either method results in the handler compile-time dependencies
being met, which allows the handler to be built, but the other dependencies
need to be resolved at the time of execution.
Before adding
libraries, check with the library provider that the library has been
tested and is supported in on OSGi environment. Some restrictions
on class loading and reflection must be adhered to. See the available
OSGi specifications for more details of these restrictions.
Choose
your method of adding the library to the project you intend to use
it in.
Procedure
To add the library to the handler OSGi bundle project:
- Add the library folder structure to the handler project. For
example, add it in the BundleContent folder.
- Find and edit the MANIFEST.MF file
in the handler project. This is usually found in the BundleContent/META-INF folder.
- In the runtime tab of the manifest editor, the Classpath
section details the locations within this OSGi bundle. Add the library .jar to
the classpath list.
To add the library to a separate OSGi bundle project,
and manage inter-bundle references:
You can find this procedure
in other OSGi documentation, but it is included for convenience here.
- Create a new OSGi bundle project using the wizard of that name
found as a result of using the menus. For this example,
name the project "myLibrary" bundle.
- Add the library folder structure to the handler project. For
example, in the BundleContent folder.
- Find and edit the MANIFEST.MF file
in the new "myLibrary" bundle project, usually found in the BundleContent/META-INF folder.
- In the runtime tab of the manifest editor, the Classpath
section details the locations within this OSGi bundle. Add the library .jar to
the classpath list.
- In the runtime tab of the manifest editor, when editing
the "myLibrary" bundle manifest, the Exported Packages section defines
which Java packages are to be made available outside of the scope for
the "myLibrary" project. Add the Java package names that are exposed
to the handler project.
- Find and edit the MANIFEST.MF file
in the handler project. In the runtime tab, add the list of Java package
names that need to be called by the handler code.