如何在不安装/激活的情况下发现OSGi捆绑软件导出的类型? [英] How to discovering types exported by OSGi bundle without installing/activating?

查看:100
本文介绍了如何在不安装/激活的情况下发现OSGi捆绑软件导出的类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我想发现jar是否实现了任何数量的接口,而无需激活或启动包.是否有可能像容器一样从API读取meta-inf中的元数据,而无需激活捆绑包?

Basically i want to discover if a jar implements any number of interfaces wihtout activating or starting the bundle. Is it possible to read the meta data from the meta-inf from an API just like the container does but without activating a bundle ?

我想使用OSGi来支持其接口将被发布的插件,并且我想知道当用户在不激活捆绑软件等的情况下上传时捆绑软件实现了哪些接口.

I want to use OSGi to support plugins of which numerous interfaces will be published and i would like to know which interfaces are implemented by a bundle when the user uploads without activating the bundle etc.

推荐答案

我认为不可能发现捆绑包将提供什么服务,因为这可以在Java代码内部进行,而无需任何元数据关于它.当然,如果使用声明式服务,则存在一个元数据文件.此外,该捆绑软件还需要导入(或提供)服务接口,这可能会给您一个提示(但不多).

I do not think it is possible to discover what services a bundle is going to provide, because this can happen from inside the Java code, without any meta-data about it. Of course, if you use Declarative Services, there is a meta-data file. Also, the bundle needs to import (or provide) the service interface, which may give you a hint (but not more).

您可以检查捆绑导入和导出的Java软件包,而无需激活它. 如果您愿意安装(不解决,不激活),则可以对其进行查询.毕竟,Felix或Equinox外壳可以列出这些软件包.

You can inspect what Java packages a bundles imports and exports without activating it. If you are willing to install (not resolve, not activate) it, you can query it. The Felix or Equinox shells can list those packages after all.

这是

Here is the relevant source from Felix' shell. It uses the PackageAdmin service:

 public void execute(String s, PrintStream out, PrintStream err)
{
    // Get package admin service.
    ServiceReference ref = m_context.getServiceReference(
        org.osgi.service.packageadmin.PackageAdmin.class.getName());
    PackageAdmin pa = (ref == null) ? null : 
        (PackageAdmin) m_context.getService(ref);

    // ... 

    Bundle bundle = m_context.getBundle( bundleId );
    ExportedPackage[] exports = pa.getExportedPackages(bundle);

    // ...
}

这篇关于如何在不安装/激活的情况下发现OSGi捆绑软件导出的类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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