1

I have an application running where I am reading a list of JAR files and loading each jar using URLClassLoader but while loading a Class from one JAR which is referring to another class from different JAR I am getting NoClassDefError.

String jbossConfigPath = System.getProperty("jboss.server.config.dir");
String jarPath = jbossConfigPath + "/somepath";
File file = new File(jarPath);
String [] jars = file.list();
URL[] jarURLs  = new URL [jars.length];
int i=0;
for(String jar : jars){
    File fileJar = new File(file,jar);
    jarURLs[i] = fileJar.toURI().toURL();
    i++;
}
URLClassLoader cl = URLClassLoader.newInstance(jarURLs,Thread.currentThread().getContextClassLoader());
Class<?> cls = ul.loadClass("com.some.class.Demo");

I am always getting NoClassDefError while loading Demo class as it is referring to Demo2 class in different JAR.

Could someone please help?

Gaël J
  • 11,274
  • 4
  • 17
  • 32
Rachit Gupta
  • 85
  • 2
  • 9

0 Answers0