How can I get class loader for given class by It’s name in OSGI?
The class is declared in another package, and may be not exported.
How can I get class loader for given class by It’s name in OSGI?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is basically impossible because the name of a class is not enough to uniquely identify it. Multiple modules may contain classes with the same name; this is an inevitable property of any module system that provides module isolation.
In fact it’s theoretically impossible in “ordinary” Java as well, because the identity of a class consists of its fully-qualified name AND its ClassLoader. So you’re asking how to get half of the identity of a class given only the other half.
If you do know which bundle/module contains the class, then you can load the class from that bundle with
Bundle.loadClass("Foo")and from the Class object you can callgetClassLoader().