Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find annotated classes in OSGi bundle

Tags:

java

jaxb

osgi

My applications has several bundles, which contain JAXB annotated classes and service bundle, which is responsible for JAXBContext creation.

The service bundle registers BundleListener and capture lifecycle events, but the problem is that I don't know how to retreive annotated classes from the org.osgi.framework.Bundle object. Adding entry with classes into MANIFEST.MF and Bundle.loadClass(..) will solve my problem, but finding classes by annotation seems more clear solution for me.

Do you have any idea how I can find annotated classes ?

I think I have to scan the jar file for .class resources with

Enumeration<?> classes = bundle.findEntries("/", "*.class", true)

and load them with Bundle.loadClass(...). Do you think that there is going to any performance issues with this approach?

like image 748
Valchev Avatar asked Dec 08 '11 07:12

Valchev


1 Answers

Searching the bundle with Bundle.findEntries does not search the Bundle-Classpath. You need to use the new BundleWiring.listResources api.

like image 110
BJ Hargrave Avatar answered Sep 21 '22 11:09

BJ Hargrave