java - ClassFormatError when defining class in OSGI environment -
i'm having problems little project i'm working on. in project i'm trying dynamically create classes configuration string , load jvm.
when in "normal" environment (unit tests) works fine. when try create classes in osgi environment (apache karaf) receive classformaterror message "illegal class name "ljava/lang/string;" in class ...".
after short research found out problem occurs classes in java/lang when not loaded system class loader i'm else expert when comes class loading in java , osgi.
i think way i'm getting access defineclass
method of interest problem here is:
protection_domain = (protectiondomain) accesscontroller.doprivileged(new privilegedaction() { public object run() { return restendpoint.class.getprotectiondomain(); } }); accesscontroller.doprivileged(new privilegedaction() { public object run() { try { class loader = class.forname("java.lang.classloader"); define_class = loader.getdeclaredmethod("defineclass", new class[]{ string.class, byte[].class, integer.type, integer.type, protectiondomain.class }); define_class.setaccessible(true); } catch (classnotfoundexception e) { throw new runtimeexception(e); } catch (nosuchmethodexception e) { throw new runtimeexception(e); } return null; } });
the last (hopefully useful) piece of information classloader invoking defineclass method on when running project in osgi bundle: instance of org.apache.felix.framework.bundlewiringimpl.
it great if me out here!
greetings, pascal
edit: need define classes @ runtime because want avoid boilerplate code in project , make program more consistent.
to more precise project restful webservice. since i'm using multiple technologies store data , snychronize processes (mongodb, mysql, activemq, ...), want use apache camel deal different technologies. problem there no possibility know of nicely integrate camel java approach on rest (the whole mapping of methods , classes http requests done annotations). possibility me write methods place parameters of request in exchange headers of camel , fire them route. avoid wanted automate process defining classes @ runtime route definitions.
write own class loader parent bundle's class loader instead of trying hack existing class loader.
Comments
Post a Comment