运行为1.5的OSX 10.9.2上的Java 1.7? [英] Java 1.7 on OSX 10.9.2 running as 1.5?

查看:129
本文介绍了运行为1.5的OSX 10.9.2上的Java 1.7?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

把头发拉出来。 java -version javac -version 都报告相同的1.7.0_45,但是当我尝试编译最简单的类时我收到一个类文件错误:

Pulling my hair out about this one. java -version and javac -version both report the same 1.7.0_45, but when I try to compile the simplest class I get a class file error:

> cat A.java
public class A {}

> javac A.java
A.java:1: cannot access java.lang.Object
bad class file: /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre/lib/rt.jar(java/lang/Object.class)
class file has wrong version 51.0, should be 49.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
public class A {}
       ^
1 error

那里当然没有安装JDK 1.5。我不认为甚至 是在JDX上运行的1.5 JDK。

There certainly is no JDK 1.5 installed. I don't think there even is a 1.5 JDK that runs on OSX any more.

FWIW,这是包含版本的frameworks目录和存根可执行文件:

FWIW, here's the frameworks directory containing the "versions" and stub executables:

> ls -al /System/Library/Frameworks/JavaVM.framework/Versions/
total 64
drwxr-xr-x  11 root  wheel  374 28 Mar 09:03 .
drwxr-xr-x  12 root  wheel  408 11 Mar 07:52 ..
lrwxr-xr-x   1 root  wheel   10 29 Oct 12:54 1.4 -> CurrentJDK
lrwxr-xr-x   1 root  wheel   10 29 Oct 12:54 1.4.2 -> CurrentJDK
lrwxr-xr-x   1 root  wheel   10 29 Oct 12:54 1.5 -> CurrentJDK
lrwxr-xr-x   1 root  wheel   10 29 Oct 12:54 1.5.0 -> CurrentJDK
lrwxr-xr-x   1 root  wheel   10 29 Oct 12:54 1.6 -> CurrentJDK
lrwxr-xr-x   1 root  wheel   10 29 Oct 12:54 1.6.0 -> CurrentJDK
drwxr-xr-x   8 root  wheel  272 28 Mar 09:03 A
lrwxr-xr-x   1 root  wheel    1 29 Oct 12:54 Current -> A
lrwxr-xr-x   1 root  wheel    1 28 Mar 09:03 CurrentJDK -> A

我检查了通常的嫌疑人,没有JAVA_HOME或CLASSPATH环境变量,不重要什么时候没有安装1.5。如果我安装JDK 8,我也会得到完全相同的行为。

I've checked the usual suspects, there's no JAVA_HOME or CLASSPATH environment variables, not that it matters when there's no 1.5 installed. I also get the exact same behaviour if I install JDK 8.

有人知道造成这种情况的原因是什么吗?

Does anybody have an idea what's causing this?

推荐答案

好的,感谢这篇文章( Java编译错误:Mac )我找到了解决方案:

OK, thanks to this post (Java compilation error: Mac) I found the solution:

rm -rf ~/Library/Java/Extensions
sudo rm -rf /Library/Java/Extensions

这篇关于运行为1.5的OSX 10.9.2上的Java 1.7?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆