1

I am wrapping Felix iPOJO in my framework call it "MyFramework", in order to simplify some of its operations.

Using MyFramework, I have the following:

1- "HelloService" Bundle, which is an iPOJO component providing a printing of "hello" message as a service.

2- "MyFrameworkComposite" bundle which is another iPOJO component that instantiates the "HelloService" component above and retrieves its services, in its start method.

3- A starter bundle which is just an OSGI bundle that instantiates the "MyFrameworkComposite" component in its start method.

4- My Java Application which loads the iPOJOs required bundles, and the above 3 bundles.

When I run my java application, I receive the following output with errors:

MyFramework Hello Service Bundle Started!
MyFramework Composite Bundle Started!
MyFramework Starter Bundle Started!
MyFramework Composite Started!
MyFramework Hello Service Component started!!
hello Component copy State is2
[ERROR]  : [adere-composite-0] The callback method start has thrown an exception : loader constraint violation: loader (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) previously initiated loading for a different type with name "org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceDescription"
java.lang.LinkageError: loader constraint violation: loader (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) previously initiated loading for a different type with name "org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceDescription"
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at .....................................(OTHER SIMILAR ERRORS)
done ok (Y)

The error occurs exactly at the following line: (This line is in my framework code):

public String[] getServiceSpecifications()
{

 return this.providedServiceDescription.getServiceSpecifications();//error here

}

providedServiceDescription is of type ProvidedServiceDescription, which is part of org.apache.felix.ipojo.handlers.providedservice package.

The line at which the error occurs is reached, when trying to retrieve the "Hello Service" component services, in my "MyFrameworkComposite" component, as the following:

ProvidedService ps= content.getProvidedService("myhelloservice.helloservice.HelloService");

I read in different resources that this can be caused when you have duplicated libraries in your class-path. But I am sure that It is not the case. What can be the cause?

Krease
  • 15,805
  • 8
  • 54
  • 86
Traveling Salesman
  • 2,209
  • 11
  • 46
  • 83

1 Answers1

3

The issue is comes from your OSGi embeddings. The class used from inside the OSGi framework and from outside are not the same because their classloader are different. You should configure your framework to avoid this issue with either:

  • by adding an extra system packages (here the iPOJO packages)
  • by adding these packages to the bootdelegation

The issue and turn arounds are described on http://felix.apache.org/site/apache-felix-framework-launching-and-embedding.html#ApacheFelixFrameworkLaunchingandEmbedding-hostserviceusage

Freiheit
  • 8,408
  • 6
  • 59
  • 101
Clement
  • 2,817
  • 1
  • 12
  • 11