【发布时间】:2016-10-17 22:07:53
【问题描述】:
我们有一个导出到 RCP 产品的插件。在插件中,有一个文件夹,里面有一些文件。如何以编程方式访问Eclipse中某个文件夹下的插件文件?
【问题讨论】:
标签: eclipse eclipse-plugin eclipse-rcp
我们有一个导出到 RCP 产品的插件。在插件中,有一个文件夹,里面有一些文件。如何以编程方式访问Eclipse中某个文件夹下的插件文件?
【问题讨论】:
标签: eclipse eclipse-plugin eclipse-rcp
使用org.eclipse.core.runtime.FileLocator 类访问插件中的文件。
Bundle bundle = ... bundle containing the files
IPath path = new Path("relative path in plug-in of the file");
URL url = FileLocator.find(bundle, path, null);
URL fileUrl = FileLocator.toFileURL(url);
FileLocator.find 方法返回的url 使用 Eclipse 特定的方案,并且只能与某些 Eclipse API 一起使用。
FileLocator.toFileURL 调用将 URL 转换为普通的 file URL,可能需要将插件 jar 解压到临时位置才能执行此操作。
您可以使用
获取Bundle
Bundle bundle = FrameworkUtil.getBundle(getClass());
获取包含当前类的包或
Bundle bundle = Platform.getBundle("plugin id");
通过插件 ID 访问包。
【讨论】: