在包中实例化iPOJO复合显示“java.lang.LinkageError:加载器约束违规:解析重写方法时”

时间:2014-01-29 18:45:26

标签: java bundle classloader ipojo linkageerror

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

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

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的快照:

enter image description here

除了我的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

我的捆绑类路径:

enter image description here

当我在我的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();

我读到here,如果两个捆绑包中有两个相同的类,则可能会出现此错误。但我无法弄清楚这两个课程的位置。我怀疑org/apache/felix/ipojo/metadata/Element但我在org.apache.felix.ipojo.中只找到了一个班级。除了我的捆绑包之外,我在其他任何地方都没有该库。

你能帮帮忙吗?感谢。

0 个答案:

没有答案
相关问题