【发布时间】:2011-04-01 04:19:56
【问题描述】:
我使用 eclipse 插件项目向导(使用 eclipse Helios)创建了两个 OSGI 包 A 和 B。
在包 B 的清单文件中,我添加了包 A 作为依赖项。此外,我已经导出了 A 中的包,因此它们对 B 可见。我在包 A 中还有一个 .properties 文件,我想让包 B 可见。在包 AI 的 build.properties 窗格中指定:
source.. = src/
bin.includes = META-INF/,\
.,\
bundle_A.properties
现在在捆绑包 B 中,我尝试使用以下方法加载 .properties 文件:
private Properties loadProperties() {
Properties properties = new Properties();
InputStream istream = this.getClass().getClassLoader().getResourceAsStream(
"bundle_A.properties");
try {
properties.load(istream);
} catch (IOException e) {
logger.error("Properties file not found!", e);
}
return properties;
}
但这会产生空指针异常(在类路径中找不到该文件)。
是否可以从包 A 导出资源(就像导出包时一样)或以其他方式从 B 访问 A 中的文件(从包 B 访问包 A 的类加载器)?
【问题讨论】: