Eclipse插件从插件包中打开PDF文件

时间:2016-09-06 08:31:17

标签: eclipse pdf plugins eclipse-plugin

我正在尝试打开一个代表我的插件文档的PDF文件,因为我使用Unknown procedure output: `rel` (line 3, column 36 (offset: 96)) "RETURN rel" 以相同的方式打开了一个属性文件。 我正在尝试使用PDF文件,我试图获取文件的URL,然后将其传递给转换为URI的getClass().getResource(URI),但它给了我Desktop.browse()例外。有没有办法更轻松地完成这项工作呢?

到目前为止,这是我的代码:

Malformed URI

1 个答案:

答案 0 :(得分:1)

您从getResource返回的网址/ URI使用的bundleresource方案很多东西都不了解。

对于Eclipse插件,您应该使用FileLocator类。

Bundle bundle = FrameworkUtil.getBundle(getClass());

IPath path = new Path("path relative to root of the plugin");

URL url = FileLocator.find(bundle, path, null);

URL fileURL = FileLocator.toFileURL(url);

Desktop.getDesktop().browse(fileURL.toURI());

FileLocator.find返回的网址再次使用了一种特殊的方案,很多东西都无法理解。 FileLocator.toFileURL将此网址转换为普通file方案 - 为此,可能需要将文件从插件jar解包到临时位置。

注意:Pathorg.eclipse.core.runtime.Path