1

我正在尝试使用 iPOJO API 创建一个复合组件。

最初,我将 felix 框架嵌入到我的 java 应用程序中,如下所示:

public class HostApplication
{
    private HostActivator m_activator = null;
    private Felix m_felix = null;


    public HostApplication()
    {
        Map config= new HashMap();

        // Create a configuration property map.
        //Map config = new HashMap();
        config.put(Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
        // Create host activator;
        m_activator = new HostActivator();
        List list = new ArrayList();
        list.add(m_activator);


        config.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, list);
         try
        {
            // Now create an instance of the framework with
            // our configuration properties.
            m_felix = new Felix(config);
            // Now start Felix instance.
            m_felix.start();
        }
        catch (Exception ex)
        {
            System.err.println("Could not create framework: " + ex);
            ex.printStackTrace();
        }


        // Register the application's context as an OSGi service!
        BundleContext bundleContext1 = m_felix.getBundleContext();

        ............

我还在我的 java 应用程序中部署 iPOJO 所需的包,如下所示:

  //starting ipojo required bundles
                    Bundle coreBundle = bundleContext1.installBundle("file:C:\\Users\\zaid.almahmoud\\Dropbox\\EBTIC\\ADERE\\feasibility-codes\\ipojo\\ipojo-distribution-1.11.0\\bundle\\org.apache.felix.ipojo-1.11.0.jar");
                    coreBundle.start();

                    Bundle compositeBundle = bundleContext1.installBundle("file:C:\\Users\\zaid.almahmoud\\Dropbox\\EBTIC\\ADERE\\feasibility-codes\\ipojo\\ipojo-distribution-1.11.0\\bundle\\org.apache.felix.ipojo.composite-1.6.0.jar");
                    compositeBundle.start();


                    Bundle apiBundle = bundleContext1.installBundle("file:C:\\Users\\zaid.almahmoud\\Dropbox\\EBTIC\\ADERE\\feasibility-codes\\ipojo\\ipojo-distribution-1.11.0\\bundle\\org.apache.felix.ipojo.api-1.6.0.jar");
                    apiBundle.start();

下面是我的 java 应用程序类路径中 jar 的快照:

在此处输入图像描述

除了我的 java 应用程序之外,我还有一个包,我在其中使用 iPOJO API 创建了一个复合组件类型。我创建了这个组合并在我的 bundle Activator start 方法中创建了一个实例,如下所示:

  public void start(BundleContext context) throws Exception {

      CompositeComponentType type = new CompositeComponentType()
      .setBundleContext(context)
      .setComponentTypeName("comp1");

      ComponentInstance ci = type.createInstance();
}

我的捆绑包的 MANIFEST.MF:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Starter
Bundle-SymbolicName: starter
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: starter.Activator
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ClassPath: .,
 org.apache.felix.ipojo-1.6.0.jar,
 org.apache.felix.ipojo.api-1.6.0.jar,
 org.apache.felix.ipojo.composite-1.6.0.jar
Export-Package: org.apache.felix.ipojo
Import-Package: org.osgi.framework, org.apache.felix.ipojo

我的捆绑类路径:

在此处输入图像描述

当我在我的 java 应用程序中安装并启动这个包时,我收到以下错误:

org.osgi.framework.BundleException: Activator start error in bundle starter...
Caused by: java.lang.LinkageError: loader constraint violation: when resolving overridden method "org.apache.felix.ipojo.composite.CompositeFactory.check(Lorg/apache/felix/ipojo/metadata/Element;)V" the class loader (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) of the current class, org/apache/felix/ipojo/composite/CompositeFactory, and its superclass loader (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5), have different Class objects for the type y.check(Lorg/apache/felix/ipojo/metadata/Element;)V used in the signature

在以下行:

ComponentInstance ci = type.createInstance();

我在这里读到,当您在两个捆绑包中有两个相同的类时,可能会出现此错误。但我不知道这两个类可能在哪里。我怀疑org/apache/felix/ipojo/metadata/Element,但我发现只有一堂课org.apache.felix.ipojo.。除了在我的捆绑包中,我在其他任何地方都没有那个库。

你能帮忙吗?谢谢。

4

0 回答 0