I am having problems dynamically loading a java class from a dynamically loaded class.
My class is an ImageJ
plugin and it loads other modules dynamically through classloader
. I have NoClassDefFoundError
when loading the module that references to something that is in the same package as the ImageJ
plugin.
What I exactly do is:
- ImageJ loads plugin (A)
- (A) gets system class loader
- (A) add jar url to class loader
- (A) try to load the desired class (B) in the jar using
Class.forName
I am unable to load class B because I get a NoClassDefFoundError
caused by B pointing to a class in A that was not found in the current classloader.
I think I need to use the same classloader ImageJ
used for loading plugins on the first place to be able to load my modules and still find references to jars previously loaded by ImageJ
. I would like to do this without having to recompile ImageJ
.
Is there any way to fix this problem without having to indagate ImageJ
code or having to modify it?
pseudo classes example
package a;
class A extends PlugInFrame {}
package a;
class C extends MyOwnPlugIn {}
package b;
import a;
class B extends C {}