java - How to load a class by classname string from OSGi runtime environment? -


i'm making bundle plug on osgi provide user function:

usercase: user input classname string , click "list" button, corresponding class decompiled , show text on gui user. 

so here problem: have classloader of bundle, how can osgi container classloader can load class name whole osgi container? (i expect when osgi starts, load bundles , class memory, class can loaded osgi container classloader if exists , able to)

anyone knows how job? sample codes highly appreciated.

i can see 2 possible situations you.

any visible class

you can add statement like

dynamicimport-package: * 

to manifest, , try load class using

class.forname("com.company.class"); 

all classes, exported or not

if need find every available class, i'm not sure why want this, try asking each bundle whether 'knows' given class. since in situation end multiple classes same name, it's pick right one.

you like

private list<class<?>> findclass(bundlecontext context, string name) {     list<class<?>> result = new arraylist<class<?>>();     (bundle b : context.getbundles()) {         try {             class<?> c = b.loadclass(name);             result.add(c);         } catch (classnotfoundexception e) {             // no problem, bundle doesn't have class         }     }     return result; } 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -