简体   繁体   中英

NoClassDefFoundError: … Caused by ClassNotFoundException

I have some simple code written by another group of people (presently unavailable), which references some jar files that I was given. When I compile the code everything builds fine, but as soon as the code tries to create an instance of a class defined in one of the jar files I get a java.lang.NoClassDefFoundError. I did a fair amount of research looking into this problem, and everything pointed to an issue with my classpath at run-time. However, when I print the classpath at run-time, I see all the jar files, and they seem to have the correct path. The run-time classpath also seems to match the compile-time classpath, so this doesn't seem to be the issue.

One thing I should mention: I'm using JDK 1.8, while I believe these jar files were created using JDK 1.7. None of the other solutions I saw mentioned this, but is there any chance this is a version compatibility issue? I haven't been able to obtain JDK 1.7 through an approved method, but if I can convincingly prove this will fix my problem I may be able to get the older version approved for install.

If it can't possibly be a version issue, where should I go from here? Every answer I've found doesn't seem to apply to my situation, but if you can point to one I may have missed or have a solution I would be very appreciative. NetBeans-specific answers are helpful, but not required. Thanks!

EDIT: For reference, here it the code I'm using to print the classpath at runtime:

    ClassLoader cl = ClassLoader.getSystemClassLoader();

    URL[] urls = ((URLClassLoader)cl).getURLs();

    for(URL url: urls){
        System.out.println(url.getFile());
    }

请确保您的编译时间和运行时代码使用了相同版本的jar文件。如果存在jar版本冲突,则可能会遇到上述问题

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM