BundleContext
的文档说它可以让你
- 获取框架中安装的包列表。
- 获取 bundle 的 Bundle 对象。
但是,没有getBundle(String symbolicName)
方法,只有getBundle(long id)
(和不合适的getBundle(String location)
. 当然,可以调用 getBundles()
并遍历返回的数组,但是有更好的方法吗?
最佳答案
我认为遍历 getBundles()
的数组很好。也许它根本不应该存在,因为符号名称不能唯一标识一个包。也许 getBundles(String symbolicName)
...
来自 OSGi 服务平台核心规范,第 4 版,版本 4.3:
3.6.2 Bundle-SymbolicName
The
Bundle-SymbolicName
manifest header is a mandatory header. The bundle symbolic name and bundle version identify a unique bundle. This does not always imply that this pair is unique in a framework, in certain cases the same bundle can be installed multiple times in the same framework, see Bundle Identifiers on page 89.
引用的第 89 页(实际上是第 95 页):
4.4.1 Bundle Identifiers
[...]
Though the pair is unique, it is possible to install the same bundle multiple times if the
org.osgi.framework.bsnversion
framework launching property is set to multiple.
关于java - 如何根据其符号名称检索 Bundle?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7977947/