Reputation: 577
I'd like to understand how OSGi handles the Java endorsed directory mechanism? I am building a bundle from a non-osgi project that uses the following endorsed jars :
I have embedded these jars in my bundle but how do I tell OSGi to treat them differently(endorsed) from the rest?
Upvotes: 1
Views: 251
Reputation: 9384
OSGi does nothing special regarding the endorsed directory. However OSGi does require all packages that do not start with "java." to be explicitly exported and imported. This means that the system bundle can export a package that could be in endorsed as well as a bundle. So another bundle that imports the package can be wired to either exporter (depending upon constraints like versioning).
So you can put this jars in endorsed by you need to make sure the system bundle is exporting those packages. See http://www.osgi.org/javadoc/r4v43/core/org/osgi/framework/Constants.html#FRAMEWORK_SYSTEMPACKAGES_EXTRA and http://www.osgi.org/javadoc/r4v43/core/org/osgi/framework/Constants.html#FRAMEWORK_SYSTEMPACKAGES. Or you can make bundles of these jars that export the packages and install them.
Upvotes: 2
Reputation: 23948
You cannot embed these JARs in your bundle; if you do this then they are no longer considered endorsed by the JVM.
Libraries that are in the endorsed directory of the JRE are loaded by the Java extension classloader, which is the parent of the main application classloader, but the child of the boot classloader. Therefore the way to expose these libraries to your bundles is to export them from the system bundle. This can be done by setting the property org.osgi.framework.system.packages.extra
to the list of additional packages to be exported.
Upvotes: 0