【发布时间】:2013-08-05 12:35:33
【问题描述】:
在我的应用程序的一个 OSGi 包中,我包含一个名为 ontologymapping.properties 的属性文件。
现在我想读取这个属性文件的内容。
在一些示例代码中,我在包的 start 方法中发现了类似的内容:
public void startObservationAdapter(BundleContext context) {
String filename = context.getProperty("ontologymapping.properties");
try {
File file = new File(filename);
InputStream in = new FileInputStream(file);
ontologymapping.load(in);
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
其中ontologymapping 是一个属性实例。
当我运行此代码时,JVM 找不到该文件。
我猜原因是该文件未包含在 BundleContext 中。
我怎样才能做到这一点?或者读取属性文件内容的另一种方法是什么?
该包不是声明性的,它是另一个声明性的 api 包。
【问题讨论】:
-
context.getProperty 不会像您认为的那样做。另外:哪个包是文件“ontologymapping.properties”,哪个包有这个代码?也就是说,为什么没有osgi.org/javadoc/r4v42/org/osgi/service/cm/…?
标签: java file-io properties osgi