java - Cross-classloader class loading -


i have customclassloader loads classes map<string, byte[]>. classes loading depend on other, unloaded classes. have jar files contain said classes in urlclassloader initiated before customclassloader, when customclassloader tried load class has external import (a jarfile in urlclassloader) exception thrown:

exception in thread "main" java.lang.noclassdeffounderror: external/class/in/urlclassloader/classimportedbyloadedclass     @ java.lang.classloader.defineclass1(native method)     @ java.lang.classloader.defineclass(classloader.java:760)     @ java.lang.classloader.defineclass(classloader.java:642)     @ customclassloader.defineclass(encryptedbytearrayclassloader.java:35) 

i need way either:

a) load classes in urlclassloader

or

b) have way set urlclassloader default classloader classes being loaded memory (instead of customclassloader)

line 35:

public class<?> defineclass(string name, byte[] bytes) {     return super.defineclass(name, bytes, 0, bytes.length); } 

i have tried setting context classloader like:

thread.currentthread().setcontextclassloader(jarloader); 

where jarloader urlclassloader.

is there way accomplish i'm trying do?

you should override classloader(classloader parent) constructor in customclassloader , pass urlclassloader there:

class customclassloader extends classloader {      public customclassloader(urlclassloader parent, ...your data...) {          super(parent);          ...      } }  customclassloader customclassloader = new customclassloader(jarloader, ...); 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

python - How to remove the Xframe Options header in django? -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -