I have defined a bundle A which contains all the common classes defining the model used by other bundles. This bundle contains an interface IDeviceHandler.
This interface is implemented by services contained in other bundles. Each service registers as a IDeviceHandler.
The bundle that represents "my application" has the following code
The main purpose is to find all the registered IDeviceHandler to register as a listener.
But a ClassCastException has been triggered.
I suspect a problem of ClassLoader. I also tried to embedd all the classes of my model (bundle A) into the other bundles. Unfortunately, it does not work (anyway it was not an "OSGi" minded solution).
Any help would be appreciated,
Thanks a lot,
Could you give me the contents of the exception? The stack trace may be of some help too.
The problem is due to class loading in OSGi. If you use (let's say) 3 bundles that refer to the same bundle "ModelBundle", the OSGi framework will consider that each class loaded from "ModelBundle" by the 3 others is different.
To solve this, you have to add the attribute "Bundle-Classpath" in the manifest file: