【问题标题】:How to get folder from OSGI bundle?如何从 OSGI 包中获取文件夹?
【发布时间】:2013-06-18 07:41:07
【问题描述】:

我有自己的 OSGI 包,里面有一些资源的文件夹。如何从 bundle 中读取该文件夹并获取它的所有子文件夹?

我在下面的代码之前使用过。:

    Bundle bundle = Platform.getBundle(bundleID);
    URL fileURL = bundle.getEntry(templatePath);
    URL url = FileLocator.resolve(fileURL);

此代码适用于我将 Eclipse 应用程序导出为 Eclipse 产品。

但我的 URL 不是分层异常。

【问题讨论】:

    标签: eclipse eclipse-plugin rcp eclipse-jdt


    【解决方案1】:

    您可以使用 Bundle 上的 findEntries 方法来定位包中的文件和任何附加的片段:

    Bundle bundle = Platform.getBundle(bundleID);
    Enumeration<URL> urls = bundle.findEntries("/folder", "*", false);
    

    【讨论】:

    【解决方案2】:

    您应该根据 InputStreams 编写代码并使用@NickWilson 建议的方法来检索输入流并在您的程序中使用它们。

    但是如果你真的需要那个文件夹在磁盘上的某个地方爆炸,你​​会使用 org.eclipse.core.runtime.FileLocator.toFileURL(URL) 而不是 resolve(URL)。

    【讨论】:

      猜你喜欢
      • 2015-07-18
      • 2012-04-03
      • 1970-01-01
      • 2014-11-07
      • 2012-07-30
      • 2014-01-18
      • 1970-01-01
      • 1970-01-01
      • 2014-01-21
      相关资源
      最近更新 更多