在OSGi捆绑包中使用受限类 [英] Use restricted class in an OSGi Bundle

查看:90
本文介绍了在OSGi捆绑包中使用受限类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要使用Endpoint使用SSL发布,我需要访问com.sun.net.httpserver.*

For publishing with SSL using the Endpoint I need to access classes under the packages com.sun.net.httpserver.*

使用Eclipse IDE,我找到了使用此类的方法.但是导出捆绑包并在另一个Equinox OSGi安装中运行它们时,我无法启动捆绑包并引发以下错误:

Using the Eclipse IDE I found a way to use this classes. But exporting the bundles and running them in another equinox OSGi Installation I can't start the bundle throwing the following error:

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

任何人如何解决此问题?

Anyone an Idea how to solve this issue?

谢谢!

推荐答案

您所引用的软件包是JDK的一部分.您需要公开它,使其在OSGi中可用,并且您有两个选择:

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

第一个(在大多数情况下是首选)选项是通过系统捆绑包公开此软件包. OSGi框架具有一个属性,您可以将其设置为执行此操作:

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

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

作为其值,除框架已公开的包之外,还为您提供要公开的包的列表,以逗号分隔.在您的情况下,至少是com.sun.net.httpserver,但是可能需要更多软件包.在这种情况下,还请确保使用此程序包的捆绑软件会导入该程序包.

As its value, you provide it with a comma separated list of packages that you want to expose, on top of the ones that are already exposed by the framework. In your case, at least com.sun.net.httpserver, but there might be more packages that you need. In this case, also make sure that the bundle that uses this package imports this package.

第二个选择是使用一种用于启动委派的机制.它只能用作万不得已的方法,因为它破坏了模块性,如果使用不当,可能会导致其他问题.同样,这是您需要设置的属性:

The second option is to use a mechanism used boot delegation. It should only be used as a last resort, as it breaks modularity and if it's not used carefully it might lead to other problems. Again, this is a property that you need to set:

org.osgi.framework.bootdelegation=*

在这里,您可以提供一个由逗号分隔的软件包列表,这些软件包应该由引导类加载器加载.支持通配符(如上例所示),但建议您尽量使用通配符,因此,例如,使用com.sun.*作为值.

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

这篇关于在OSGi捆绑包中使用受限类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆