I created a Bundle in Eclipse, and used the "Launch the Framework" link for the "Overview" tab. I have created an interface (TestService) in my bundle, and code that should generate a proxy for it (in Helper). I call this code in the Activator of the Bundle, and get:
Caused by: javassist.NotFoundException: com.test.services.TestService
at javassist.ClassPool.get(ClassPool.java:436)
at com.test.services.Helper.get(Helper.java:46)
It throws right at the first ClassPool.get():
ClassPool pool = ClassPool.getDefault();
CtClass result = pool.get(TestService.class.getName());
...
TestService is public and in the same package, and Bundle, as the Helper, which generates the Exception. Obviously, it's not good enough to just do "ClassPool.getDefault()". So what do I need to do so that ClassPool sees the classes inside the Bundle? Do I have to import my own packages?
If "source" is an object loaded by an OSGi bundle classloader, you can the corresponding "classpath" (or classloader) to the ClassPool, like this:
pool.insertClassPath(new ClassClassPath(source.getClass()));
or in your case simply
pool.insertClassPath(new ClassClassPath(TestService.class));
Hope it helps.
I use javassist in some OSGi bundles to modify/generate Java classes on the fly. You can just look here. Hope it helps you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With