且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将 org.pbjar 库转换为 OSGi 包后出错

更新时间:2023-11-17 21:37:46

所以你的包尝试导入 com.sun.java.swing 包,当框架尝试解析包时,它找不到任何人导出这个包.这就是错误消息试图告诉您的内容.

So your bundle tries to import the com.sun.java.swing package, and when the framework tries to resolve the bundle, it cannot find anybody exporting this package. That is what the error message is trying to tell you.

在 Java 7 中(我没有检查过旧版本)这个包是 JRE 的一部分.这意味着将它公开给包的最简单方法是让框架将其作为额外"包导出.您可以在启动框架时配置系统属性来执行此操作:

In Java 7 (I have not checked older versions) this package is part of the JRE. This means the easiest way to expose it to bundles is by having the framework export it as an "extra" package. You can configure a system property when starting your framework to do that:

-Dorg.osgi.framework.system.packages.extra=com.sun.java.swing

您拥有的另一种选择是将此包嵌入到您的包中.在这种情况下,您不需要通过框架导出它(这在您无法重新配置框架的情况下很方便)并且导入包也可以从您的包中删除.如果您最终有很多需要这个的包,这可能不是那么方便或好,因为您最终会得到包的许多私人副本(而不是每个人共享一个).

The other alternative you have is to embed this package inside your bundle. In that case you don't need to export it via the framework (which is convenient in case you cannot reconfigure your framework) and the import package can be removed from your bundle as well. If you end up having many bundles that need this, this is probably not that convenient or good, as you will end up with many private copies of the package (instead of everybody sharing one).