by
0
5
3,028
3
Top 1% !
Popular
Famous
Specified
OpenSource
Popularity: 4633rd place
Created
Modified Nov 14, 2013

Published on:

No tags for this snippet yet.
JVMjre6
LanguageJava
LicenseMIT_X11
Target FrameworkOSGi
TechnologyOSGi

How to Retrieve the list of classes in a package under OSGi

This method lists the classes contained in a package of the given bundle under OSGi environment.
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/12312/How-to-Retrieve-the-list-of-classes-in-a?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
public List<Class<?>> getClassesOfPackage(Bundle b, String packageName) { BundleWiring wiring = b.adapt(BundleWiring.class); Collection<String> classNames = wiring.listResources(packageName.replace('.', '/'), null, BundleWiring.LISTRESOURCES_LOCAL); List<Class<?>> result = new ArrayList<Class<?>>(); for (String cName : classNames) { Class<?> c = null; try { c = b.loadClass(cName.replace(".class", "").replace('/', '.')); } catch (ClassNotFoundException e) { continue; } if (c != null) result.add(c); } return result; }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus