Search code examples
javajaxbosgi

How to find annotated classes in OSGi bundle


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?


Solution

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