3

These are in my /usr/bin:

lrwxr-xr-x   1 root   wheel        73 Aug 21 18:18 javap -> /Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home/bin/javap
lrwxr-xr-x   1 root   wheel        73 Aug 21 18:18 javah -> /Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home/bin/javah
lrwxr-xr-x   1 root   wheel        82 Aug 21 18:18 javafxpackager -> /Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home/bin/javafxpackager
lrwxr-xr-x   1 root   wheel        75 Aug 21 18:18 javadoc -> /Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home/bin/javadoc
lrwxr-xr-x   1 root   wheel        73 Aug 21 18:18 javac -> /Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home/bin/javac
lrwxr-xr-x   1 root   wheel        72 Aug 21 18:18 java -> /Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home/bin/java

which all point to JDK v1.7.x.

I'm running Max OS X 10.9.4. I stupidly attempted to downgrade from 1.8 to 1.7, which caused these issues. Trying to run javac -version throws this stack trace:

zhickman:bin zhickman$ javac -version
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/sun/tools/javac/Main : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:412)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)

However, running java -version gives me:

zhickman:bin zhickman$ java -version
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

I think I've updated my symlinks incorrectly. I understand the "Unsupported major.minor version..." error is common, but I've only seen solutions that involve compiled code attempting to be run that cause this issue.


Extra notes:

zhickman:bin zhickman$ $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home
ಠ_ಠ
  • 3,060
  • 28
  • 43
  • As a first measure, you should confirm which `javac` is executed: `which javac`. – Marko Topolnik Aug 25 '14 at 16:57
  • Furthermore, just running `java -version` doesn't probably even attempt to start a JVM; it just runs native code which prints the version information. If you try to actually *run* some java program, you may find it fails as well. – Marko Topolnik Aug 25 '14 at 16:59
  • @MarkoTopolnik `which javac` returns `/usr/bin/javac` thankfully. – ಠ_ಠ Aug 25 '14 at 17:05
  • how did you perform your downgrade attempt? – Marko Topolnik Aug 25 '14 at 17:07
  • I manually `rm -rf`d the jdk1.8 folder at `/Library/Java/JavaVirtualMachines/`, and then updated the symlinks to point towards the jdk1.7 folder – ಠ_ಠ Aug 25 '14 at 17:09
  • Just to check... what does `/usr/libexec/java_home` give you? – Marko Topolnik Aug 25 '14 at 17:12
  • Clearly there is *something* left over from Java 8, which is being used by Java 7's javac. The only thing I can think of is a Java 8 JRE which somehow gets involved. Java path resolution on Mac is notoriously convoluted. – Marko Topolnik Aug 25 '14 at 17:16
  • I set my java home to `/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home`. I agree that a Java 8 JRE is involved somewhere, I just can't for the life of me find it. – ಠ_ಠ Aug 25 '14 at 17:20
  • Just to clarify the `java_home` comment: this is not related to the `JAVA_HOME` variable; it is a binary executable which resolves the java home directory in an OS X-specific manner, consulting `info.plist` files and more. It is generally your best bet at resolving the "current" Java home. – Marko Topolnik Aug 25 '14 at 19:12
  • Ah right, my `java_home` was pointing to 1.7. – ಠ_ಠ Aug 25 '14 at 20:15

2 Answers2

3

It turns out I needed to remove /Library/Java/Extensions, which contained tools.jar that I assume referenced JRE8.

ಠ_ಠ
  • 3,060
  • 28
  • 43
  • That's strange... my Extensions does not contain tools.jar and it is in fact quite unusual that it would contain it, since it is a standard JDK jar, residing in Home/lib. It might be a leftover from an early-access Java 8 version, if you had used it. – Marko Topolnik Aug 25 '14 at 19:09
0

I use both Java 8 and Java 7. This error ie. Unsupported major.minor version 52.0 occurs for me sometimes while changing from Java 8 to Java 7. I use eclipse in Windows. What I have observed is that when you downgrade from Java 8 to Java 7, you also have to change the Java compiler compliance from 1.8 to 1.7. This solves the error. I do not know much about Mac OS X, but if you can change the compiler compliance from 1.8 to 1.7, it will fix the error.

Soumasish
  • 53
  • 1
  • 9
  • Since I am not using Eclipse, I would need a way of changing "compiler compliance" from the command line. – ಠ_ಠ Aug 25 '14 at 17:41
  • See this link: http://stackoverflow.com/questions/18162519/set-java-complier-compliance-level – Soumasish Aug 25 '14 at 17:43
  • Unfortunately, still throws the same error. And, when I use Maven, I would need it to be able to select its own compiler versions at runtime. – ಠ_ಠ Aug 25 '14 at 17:45