Java Reflections'NoClassDef'错误

时间:2015-06-14 14:01:00

标签: java reflection runtime-error

我正在尝试使用自定义库反射浏览已实现接口的所有类。这是我的来源:

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;
}

错误:

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

mod.api.core包退出。所以这不应该是错误。

1 个答案:

答案 0 :(得分:4)

java.lang.NoClassDefFoundError:javassist / bytecode / ClassFile

您可以通过将javassist-3.12.1.GA.jar添加到类路径

来解决此问题