I'm really struggling with this. I've been unable to configure Intellij to use Javac, unable to run javadoc. I just can't seem to get my java runtime environment stable and working productively on Mac OSX.
I've created the most basic of examples which is a hello world program and it still errors from command line. Everything I read about this error tells me to "upgrade the compiler". But I'm really not sure what the problem is, the javac & java are both running 1.8 (now, after I tried upgrading the system JVM).
I explicitly set the path when calling javac, checked the version etc. Everything tells me it's 1.8.
Can anyone explain how to fix this? (without reverting my system to a 1.5 SDK).
This is output from the basic hello world application:
$JAVA_HOME/bin/javac Main.java
Main.java:3: cannot access java.lang.Object
bad class file: /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/rt.jar(java/lang/Object.class)
class file has wrong version 52.0, should be 49.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
public class Main {
^
1 error
localhost:mycompany$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
localhost:mycompany$
Output from javac version:
javac -version
javac 1.8.0_45
javac: no source files
Usage: javac <options> <source files>
Output from java version:
java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
The error message means that you try to load a Java 8 class with a Java 5 VM.
For an unknown reason $JAVA_HOME/bin/javac
is using the JDK 8 Java runtime (.../rt.jar
) but the compiler itself is loaded with a Java 5 VM.
My next step would be to make sure that $JAVA_HOME/bin/javac
is actually what it should be (and not a script which does something weird). I'd also check the environment (CLASSPATH
) and options like -Xbootclasspath
. Try set | grep -i java
and set | grep -i path
to look for suspicious variables.
If nothing seems to work, try to reinstall the Java 8 SDK again.
I had exactly the same issue with the same versions when trying to build the Arduino IDE using ant. The fix is to remove an old version of tools.jar from /Library/Java/Extensions/
- just wanted to clarify for others that hit the same issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With