java - Calling a outside class method from Jar class -
i have created class "class b
"
package com.b public class b { public void printmsg() { system.out.println("called"); } }
i have created jar file below class "class a
"
package com.a import com.b public class extends b { }
when tried load jar dynamically using below code, getting error "class b
" "classnotfoundexception
"
classloader cl = new urlclassloader(new url[] { new url(jarfullpath) }); class<?> cla = cl.loadclass(classname); object obj = cla.newinstance();
i believe because did not provide parent classloader
urlclassloader
such can find a
not b
, try instead:
classloader cl = new urlclassloader( new url[] {new url(jarfullpath)}, thread.currentthread().getcontextclassloader() );
this use thread.currentthread().getcontextclassloader()
parent classloader
corresponding context classloader
.
Comments
Post a Comment