Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java 1.7 on OSX 10.9.2 running as 1.5?

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

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, 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

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?

like image 855
Sophistifunk Avatar asked Mar 27 '14 22:03

Sophistifunk


People also ask

Can I have two versions of Java on my Mac?

jenv makes it easy to run multiple versions of Java on a Mac computer. It also makes it easy to seamlessly switch between Java versions when you switch projects. Running multiple Java versions is important for Android and Apache Spark developers.


1 Answers

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

rm -rf ~/Library/Java/Extensions
sudo rm -rf /Library/Java/Extensions
like image 157
Sophistifunk Avatar answered Oct 11 '22 14:10

Sophistifunk