Getting NoClassDefFoundError even tho the system can see the class ist is meant to load

29 Views Asked by At

The code block below is inside a function that accesses a jar file. I have already checked to see if the path to the file is correct. When printing the classnames from the jar file to the console, i see all the correct classnames. "model_with_HSQLDB_1_8.HSQLDB_Local_Model_1_8" is among one of those class names. When i try to load that class using the code below, i get an error.


Class myClass = getClassFromJarFile(jarfile, "model_with_HSQLDB_1_8.HSQLDB_Local_Model_1_8");


public static Class getClassFromJarFile(File jarfile, String className){

    try (URLClassLoader cl = URLClassLoader.newInstance(
                 new URL[] { new URL("jar:file:" + jarFile + "!/") })) { 

        return cl.loadClass(className);
    }
}

The cl.loadClass() throws the Error.

I get the following error message:

    Exception in thread "main" java.lang.NoClassDefFoundError: interfaces/Modelable_1_8...
    Caused by: java.lang.ClassNotFoundException: interfaces.Modelable_1_8

the weird thing is that the error is "java.lang.ClassNotFoundException: interfaces.Modelable_1_8" instead of something like "java.lang.ClassNotFoundException: model_with_HSQLDB_1_8.HSQLDB_Local_Model_1_8"

Any help on this topic would be great!

0

There are 0 best solutions below