简体   繁体   English

Eclipse:如何从包中检索资源

[英]Eclipse: How to retrieve a resource from a bundle

I am using this code to retrieve a folder from a bundle 我正在使用此代码从包中检索文件夹

URL url = Platform.getBundle("myBundle").getEntry("myFolder");
File fileTmp = null;
try {
     fileTmp = new File(FileLocator.resolve(url).toURI());
} catch (URISyntaxException e1) {
  // TODO Auto-generated catch block
  e1.printStackTrace();
 } catch (IOException e1) {
  // TODO Auto-generated catch block
  e1.printStackTrace();
}

The problem is that although it works if I run it as an Eclipse Application, it does not if i export it in the dropins folder and restart Eclipse. 问题是,尽管如果我将其作为Eclipse应用程序运行,它可以工作,但是如果我将其导出到dropins文件夹中,然后重新启动Eclipse,则无法使用。 In this case it seems the FileLocator fails to resolve the url. 在这种情况下,FileLocator似乎无法解析该URL。 Am i missing something? 我想念什么吗?

UPDATE I have opened the jar of the exported plugin and I can't actually find the folder I am trying to retrieve. 更新我已经打开了导出插件的jar,但实际上找不到我要检索的文件夹。 There has to be something that I should configure before to export the plugin in order to export the folder as well. 在导出插件之前,还必须配置一些内容,以便导出文件夹。 How can I do that? 我怎样才能做到这一点?

See this: Eclipse: how to export a folder in a plugin 参见以下内容: Eclipse:如何在插件中导出文件夹

而是使用Platform ,尝试通过AbstractUIPlugin实现(如果有)获取资源,例如: Application.getDefault().getBundle().getResource(name)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM