简体   繁体   English

NoClassDefFoundError:…由ClassNotFoundException引起

[英]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. 我有另一组人(目前不可用)编写的一些简单代码,这些代码引用了我得到的一些jar文件。 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. 当我编译代码时,一切都构建良好,但是一旦代码尝试创建在一个jar文件中定义的类的实例,我就会得到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. 但是,当我在运行时打印类路径时,我看到了所有的jar文件,它们似乎具有正确的路径。 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. 我应该提到的一件事:我正在使用JDK 1.8,而我相信这些jar文件是使用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. 我无法通过批准的方法获得JDK 1.7,但是如果我可以令人信服地证明这可以解决我的问题,则可以使较旧的版本获得批准以进行安装。

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. NetBeans特定的答案很有帮助,但不是必需的。 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版本冲突,则可能会遇到上述问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决ClassNotFoundException引起的NoClassDefFoundError? - How to solve a NoClassDefFoundError caused by ClassNotFoundException? loadClass抛出由ClassNotFoundException引起的NoClassDefFoundError - loadClass throws NoClassDefFoundError caused by ClassNotFoundException 类声明错误(由ClassNotFoundException引起的NoClassDefFoundError) - Class declaration bug (NoClassDefFoundError caused by ClassNotFoundException) 难道NoClassDefFoundError总是有ClassNotFoundException引起的吗? - Does NoClassDefFoundError have always ClassNotFoundException in caused by? 由java.lang.NoClassDefFoundError和ClassNotFoundException引起的错误 - Error caused by java.lang.NoClassDefFoundError and ClassNotFoundException 将 Java Web 应用程序部署到 Heroku:由 ClassNotFoundException 引起的 NoClassDefFoundError - deploying java web app to heroku: NoClassDefFoundError caused by ClassNotFoundException ClassNotFoundException 导致的线程“主”java.lang.NoClassDefFoundError 中的异常 - Exception in thread "main" java.lang.NoClassDefFoundError caused by ClassNotFoundException NoClassDefFoundError原因:java.lang.ClassNotFoundException:junit.textui.ResultPrinter - NoClassDefFoundError Caused by: java.lang.ClassNotFoundException: junit.textui.ResultPrinter 在Hive驱动程序连接线上的Hadoop中由ClassNotFoundException引起的NoClassDefFoundError? - NoClassDefFoundError caused by ClassNotFoundException in Hadoop on Hive Driver Connection line? NoClassDefFoundError和ClassNotFoundException - NoClassDefFoundError and ClassNotFoundException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM