How to discovering types exported by OSGi bundle without installing/activating?

前端 未结 2 1218
执笔经年
执笔经年 2020-12-19 20:26

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 f

2条回答
  •  时光说笑
    2020-12-19 20:46

    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).

    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);
    
        // ...
    }
    

提交回复
热议问题