访问另一个osgi包中的资源? [英] Access resources in another osgi bundle?

查看:140
本文介绍了访问另一个osgi包中的资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用eclipse插件项目向导(使用eclipse Helios)创建了两个OSGI捆绑包A和B.

I have created two OSGI bundles A and B using the eclipse Plug-in project wizard (using eclipse Helios).

在包B的清单文件中,我添加了捆绑包A作为依赖关系。此外,我已经导出了A中的包,所以它们是可见的。我也有一个包A中的.properties文件,我想让bundle B可见。在包AI中的build.properties窗格中指定了: p>

In the manifest file of bundle B I have added bundle A as a dependency. Further I have exported the packages in A so they are visible for B. I also have a .properties file in bundle A that I would like to make visible for bundle B. In the build.properties pane in bundle A I have specified:

source.. = src/
bin.includes = META-INF/,\
               .,\
               bundle_A.properties

现在在捆绑BI尝试使用以下方式加载.properties文件:

Now in bundle B I try to load the .properties file using:

  private Properties loadProperties() {
    Properties properties = new Properties();
    InputStream istream = this.getClass().getClassLoader().getResourceAsStream(
        "bundle_A.properties");
    try {
      properties.load(istream);
    } catch (IOException e) {
      logger.error("Properties file not found!", e);
    }
    return properties;
  }

但是这给了一个nullpointer异常(该类路径上找不到该文件)

But that gives a nullpointer exception (the file is not found on the classpath).

是否可以从捆绑包A导出资源(就像导出包时一样),或以某种方式以另一种方式从B访问A中的文件(访问Classloader for捆绑A从捆绑B)?

Is it possible to export resources from bundle A (just like when you export packages) or somehow access the file in A from B in another way (accessing the classloader for bundle A from bundle B)?

推荐答案

如果你正在编写一个Eclipse插件,你可以尝试一下: p>

If you're writing an Eclipse plug-in you could try something like:

Bundle bundle = Platform.getBundle("your.plugin.id");

Path path = new Path("path/to/a/file.type");

URL fileURL = Platform.find(bundle, path);

InputStream in = fileURL.openStream();

这篇关于访问另一个osgi包中的资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆