Java Reflections 'NoClassDef' error

7.6k Views Asked by At

I'm trying to browse all classes that have implemented an interface using the custom libary Reflections. Here is my source :

public static List<IModdable> getAllModClasses() {
    Reflections reflections = new Reflections("mod.api.core"); //getting error here
    Set<Class<? extends IModdable>> classes = reflections.getSubTypesOf(IModdable.class);
    List<IModdable> modList = new ArrayList<IModdable>();
    for (Class<? extends IModdable> c : classes)
        try {
            modList.add((IModdable) c.newInstance());
        } catch (Exception ex) {
            err(String.format("Could not load mod %s !", c.getName()));
        }


    return modList;
}

error:

Exception in thread "Client thread" java.lang.NoClassDefFoundError: javassist/bytecode/ClassFile
    at org.reflections.adapters.JavassistAdapter.getOfCreateClassObject(JavassistAdapter.java:100)
    at org.reflections.adapters.JavassistAdapter.getOfCreateClassObject(JavassistAdapter.java:24)
    at org.reflections.scanners.AbstractScanner.scan(AbstractScanner.java:30)
    at org.reflections.Reflections.scan(Reflections.java:238)
    at org.reflections.Reflections.scan(Reflections.java:204)
    at org.reflections.Reflections.<init>(Reflections.java:129)
    at org.reflections.Reflections.<init>(Reflections.java:170)
    at org.reflections.Reflections.<init>(Reflections.java:143)
    at mod.api.core.CoreProvider.getAllModClasses(CoreProvider.java:17)
    at mod.api.core.ModCore.onLoad(ModCore.java:13)
    at net.minecraft.client.Minecraft.run(Minecraft.java:405)
    at net.minecraft.client.main.Main.main(Main.java:114)
    at Start.main(Start.java:11)
Caused by: java.lang.ClassNotFoundException: javassist.bytecode.ClassFile
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 13 more

The mod.api.core package exits. So that shouldn't be the error.

1

There are 1 best solutions below

1
On BEST ANSWER

java.lang.NoClassDefFoundError: javassist/bytecode/ClassFile

You can fix the issue by adding javassist-3.12.1.GA.jar to your classpath