我正在使用 Eclipse Plugin-in-project 开发一个 Eclipse 插件,它将在工具栏中添加一个菜单项。
我的插件项目依赖于位于同一插件项目中的一个文件,我想要该文件的路径。
下面是我用来获取路径的示例代码:
Bundle bundle = Platform.getBundle("com.feat.eclipse.plugin");
URL fileURL = bundle.getEntry("webspy/lib/file.txt");
File file = null;
String path=null;
try {
file = new File(FileLocator.resolve(fileURL).toURI());
path = file.getAbsolutePath();
} catch (URISyntaxException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
从 Eclipse 运行时运行方式 > Eclipse 应用程序它给了我正确的道路。但是当我将插件导出为 jar 并将其添加到我的 Eclipse 插件文件夹中时,它没有给我正确的路径。
请帮我解决这个问题!
Use:
URL url = FileLocator.find(bundle, new Path("webspy/lib/file.txt"), null);
url = FileLocator.toFileURL(url);
File file = URIUtil.toFile(URIUtil.toURI(url));
当你的文件打包在 jar 中时FileLocator.toFileURL
将它们复制到临时位置,以便您可以使用File
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)