【问题标题】:Image path inside an eclipse plugineclipse插件内的图像路径
【发布时间】:2012-08-24 16:40:21
【问题描述】:

我正在尝试通过以下方式(来自 eclipse FAQ 网站上的教程)引用 eclipse 插件中的图像(例如图标):

Bundle bundle = Platform.getBundle(PLUGIN_ID);
Path path = new Path("icons/doodledebug-icon.png");
URL fileURL = FileLocator.find(bundle, path, null);
URL resolved = null;
try {
    resolved = FileLocator.resolve(fileURL);
} catch (IOException e) {
    throw new RuntimeException(e);
}
ImageDescriptor imageDescriptor = ImageDescriptor.createFromURL(resolved);

这在测试时工作正常,即在运行时 eclipse 应用程序中。但是在创建更新站点并使用此站点时会导致错误。路径似乎在语法上不正确:

C:\Program Files\eclipse EE indigo\file:\C:\Users\Me\.eclipse\org.eclipse.platform_3.7.0_1202875443\plugins\DoodleDebugServer-Plugin_1.0.0.201208241809.jar!\icons\doodledebug-icon.png

为什么在 jar 中执行时会中断,或者我应该如何正确执行此操作?

【问题讨论】:

    标签: java jar eclipse-plugin filepath


    【解决方案1】:

    假设icons目录在项目的根目录,相信你可以在路径前面加一个斜线:

    Path path = new Path("/icons/doodledebug-icon.png");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-09
      • 2023-03-20
      • 2011-07-10
      • 2017-11-07
      • 1970-01-01
      • 2013-03-31
      • 2011-12-22
      相关资源
      最近更新 更多