Mac 10.5 上的 java.lang.NoClassDefFoundError

发布于 2024-10-31 13:34:24 字数 874 浏览 6 评论 0原文

前几天,当我尝试运行一个朋友用 java 1.6 编译的 jar 文件时,我的问题就开始了。然后我得到:

java.lang.NoClassDefFoundError

因为显然我只使用 java 1.5。所以我使用系统更新进行更新。这没有帮助,当我运行:

java -version

在终端中它仍然说我有 java 1.5。然后我在互联网上看到苹果下载页面上有一个“java SE update 4”。我下载并安装了这个文件,但它仍然无法工作。我放弃了,决定继续在 eclipse 中编程。当我尝试在 Eclipse 中编译并运行我的应用程序时,我收到了相同的错误 java.lang.NoClassDefFoundError 并且它不允许我继续。我尝试右键单击该项目并查看属性,但它不允许我这样做,只是给了我另一个错误。我想当我安装新的java版本时我可能会搞砸一些东西,所以我尝试重新安装eclipse,但它仍然给了我同样的错误。我尝试创建一个新的工作区,但这也无济于事。然后我想我会尝试使用以下命令通过终端进行编译:

javac main.java
java main

但我仍然遇到相同的错误。我进入系统设置并禁用“java 1.6”,我尝试使用 javaSE-5 和 javaSE-6 创建新项目,但它不起作用。我现在的想法是,这是否与 eclipse 无法访问 bin 和 eclipse 有关。项目目录中的 src 目录但是如果我重新安装它应该可以工作吗?我还看到有人提到在 os x 中设置类路径,但我不知道。我真的需要一些帮助来解决这个问题,因为我的很多工作都依赖于 eclipse 工作。我宁愿不必因为这个而重新安装整个操作系统,但如果我无法让它工作,我想没有其他选择。

此致 乔纳斯·克里斯滕森

My problem started the other day when I tried to run a jar file that was compiled in java 1.6 from a friend. I then got:

java.lang.NoClassDefFoundError

Since I was only using java 1.5 obviously. So I updated using the system update. This did not help and when I ran:

java -version

in the terminal it still said I had java 1.5. I then saw on the internet that there was an "java SE update 4" on apples download page available. I downloaded and installed this file but it still wouldn't work. I gave up and decided to go back to my programming in eclipse. When I tried to compile and run my application in eclipse I now recieved the same error java.lang.NoClassDefFoundError and it wouldnt let me proceed. I tried right clicking the project and viewing the properties but it wouldnt let me, just gave me another error. I figured I might messed something up when I installed the new java version so I tried reinstalling eclipse but it still gave me the same error. I tried creating a new workspace but that wouldnt help either. I then figured I would try to compile throught the terminal using:

javac main.java
java main

But I still get the same error. I went in under systems settings and diabled "java 1.6" and i tried creating new projects with both javaSE-5 and javaSE-6 but it just wont work. My thoughts now is if it has something to do with eclipse not being able to access the bin & src directories in the project directory but that should work if i reinstalled it? I also saw someone mention setting the classpath in os x but I don't know. I would really need some help solving this issue since a lot of my work rely on eclipse working. I would rather not have to reinstall the whole OS just because of this but if I can't get it to work I guess there is no other alternative.

Best Regards
Jonas Kristensson

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

幸福不弃 2024-11-07 13:34:25

“重新安装整个操作系统”?天哪,不。

你的问题与Java版本无关。你不明白 CLASSPATH 是如何工作的。

您尝试运行的类不在 CLASSPATH 中。如果您的朋友给了您一个 JAR,您需要将其添加到您的 CLASSPATH 并使用完全解析的类名来运行它。

对您未来心理健康的建议:当您遇到问题时,不要做最坏的打算并采取极端措施。首先尝试简单的解决方案。

"Reinstall the whole OS"? Good lord, no.

Your problems have nothing to do with the version of Java. You don't understand how CLASSPATH works.

The class you were trying to run wasn't on the CLASSPATH. If your friend gave you a JAR, you need to add it to your CLASSPATH and use the fully-resolved class name to run it.

A word of advice for your future mental health: When you have problems, don't assume the worst and jump to extreme measures. Try the simple solutions first.

错々过的事 2024-11-07 13:34:25

我尝试运行一个朋友用java 1.6编译的jar文件。 ...因为我显然只使用 java 1.5

请注意,如果确实是这种情况,您将收到 java.lang.UnsupportedClassVersionError,因为 Java 5 无法运行为 Java 6 编译的类(它也许可以这样做,但类文件说“我是 Java 6+”(类版本 50),因此 Java 5 将拒绝运行它(Java 5 中的最大类版本为 49)。

I tried to run a jar file that was compiled in java 1.6 from a friend. ... Since I was only using java 1.5 obviously

Note that if this was really the case you'd get a java.lang.UnsupportedClassVersionError, since Java 5 can't run classes compiled for Java 6 (it might be able to do so, but the class files say "I'm Java 6+" (class version 50) and thus Java 5 would just refuse to run it (max class version in Java 5 would be 49).

疧_╮線 2024-11-07 13:34:25

尝试编译

javac -source 1.5 target 1.5 .....

Try to compile with

javac -source 1.5 target 1.5 .....
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文