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

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -