[英]how to load a file from the bundle in eclispe rcp
I am loading a property file in the eclipse bundle but my code is using InternalPlatform
from eclipse package which is not the best way to do that because it is restricted package from the eclipse . 我正在eclipse软件包中加载属性文件,但是我的代码使用的是eclipse软件包中的
InternalPlatform
,这不是最好的方法,因为它是eclipse的受限软件包。 How do I load this file from the classpath. 如何从类路径加载此文件。
public Properties getProperties(String resourceName){
Bundle bundle = InternalPlatform.getDefault().getBundle("sample-bundle");
try {
return PropertyFactory.getProperties(new URL("platform:/plugin/" + bundle.getSymbolicName() + "/" + resourceName));
} catch (Exception e) {
logger.error("Unable to load aegis config {}", e.getMessage(), e);
return null;
}
private static Properties getProperties(URL url) throws IOException {
Properties properties = new Properties();
logger.info("Loading Properties from {}", url);
properties.load(url.openStream());
return properties;
}
The Platform
class provides an official way to get the bundle for a plugin given its id: Platform
类提供了一种获取给定ID的插件包的官方方法:
Bundle bundle = Platform.getBundle("sample-bundle");
You can then use the FileLocator
class to find a resource in the bundle: 然后,您可以使用
FileLocator
类在FileLocator
包中查找资源:
IPath path = new Path("relative path of resource in bundle");
URL url = FileLocator.find(bundle, path, null);
Note: Platform
is org.eclipse.core.runtime.Platform
in the org.eclipse.core.runtime
plugin. 注:
Platform
是org.eclipse.core.runtime.Platform
在org.eclipse.core.runtime
插件。 Path
is org.eclipse.core.runtime.Path
. Path
是org.eclipse.core.runtime.Path
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.