Use constrained class in OSGi collection

To publish using SSL using endpoint I need to access the classes under packages com.sun.net.httpserver.*

Using Eclipse IDE I found a way to use these classes. But while exporting packages and running them on a different OSGi Equinox installation, I cannot run the package, causing the following error:

java.lang.NoClassDefFoundError: com/sun/net/httpserver/HttpsConfigurator

      

Any idea how to fix this problem?

Thank!

+1


source to share


1 answer


The package you mean is part of the JDK. You need to expose it to make it available in OSGi and you have two options:

The first, and in most cases the preferred option, is to expose this package through the system package. The OSGi framework has a property that you can set to do this:

org.osgi.framework.system.packages.extra=...

      

As your value, you provide it with a comma-separated list of packages you want to open, on top of those already exposed by the framework. In your case, at least com.sun.net.httpserver, but there may be more packages you need. In this case, also make sure that the package that uses this package will import this package.



The second option is to use the mechanism used to delegate the download. It should only be used as a last resort as it breaks modularity and if not used carefully it can lead to other problems. Again, this is the property you need to set:

org.osgi.framework.bootdelegation=*

      

Here you can provide a comma separated list of packages to be loaded by the load class loader. Wildcards are supported (as shown in the example above), but you are encouraged to be as specific as possible, so in your case, for example, use com.sun. * As a value.

+6


source







All Articles