osgi bundle exports class, but still class in classpath being picked up
I am trying to use deploy an ear with a webapp that uses an osgi bundle and exports some classes. This is in an appserver. the bundle exports class A which derivbes from class B. ClassB is really a 3rd party opensource class, which the bundle has decided to provide. The problem is my ear also has another version of classB in the ear's lib directory.
On attempting to deploy the applicat开发者_如何学Goion, I am getting a strange error, the class A is loaded from osgi bundle jar, but since classB is loaded from the ear's lib directory and not from the osgi bundle, even though its there.
This is leading to errors resulting from the classA expecting some behavior to be there in its baseclass, but in reality does not exist because classB is loaded form outside the bundle.
I am not sure how to fix this- this is my first encounter with osgi and i am a little concerned that this could be worse than classpath hell, especially for apps that require integration with parts of it being osgi and parts of it not.
I know that people are trying to mix Java EE and OSGi stacks, but I think that it's a recipe for problems. They both have their own expectations for how classloaders work and getting them to cooperate can be a problem.
If you must do this, you can make life easier for yourself by putting as much as possible of your web app in the osgi container. Alternatively, find the place where the osgi runtime is initialized and change how its parent's classloader is wired in. You can even write a custom filtering classloader that would prevent certain classes from being loaded by OSGi from webapp classloader. Many things are possible, but perhaps you don't really want to go down this path...
精彩评论