I had a compilation problem with Eclipse with 1.7 JDK installed running on Mavericks:
class file has wrong version 51.0, should be 49.0
So, as this looked like a javac versioning problem I removed all java versions. Installed 1.7_51, installed the Apple supplied 1.6 version so that Eclipse would run, changed sym links so 1.7 was the default. Same problem as before, the same project would not compile, though others did,
Next step, strip the problem down to the bare bones i.e. remove ant etc from the equation - Test.java file used has no methods, just a main with System.out.println(). cd to the directory containing the source file and ran the compiler specifying full path to javac, having checked that JAVA_HOME was not set:
$
/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/bin/javac
Test.java -verbose -extdirs . -endorseddirs . -cp . -bootclasspath
/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib/rt.jar
-version
Output:
javac 1.7.0_51
[parsing started Test.java]
[parsing completed 67ms]
[search path for source files: [.]]
[search path for class
files:[/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib/rt.jar,
.]]
[loading
/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib/rt.jar(java/lang/Object.class)]
Test.java:11: cannot access java.lang.Object bad class file:
/Library/Java/JavaVirtualMachines/jdk1.7.0_51.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 Test {
^
[total 336ms] 1 error
Flumoxed.
Any ideas ?
On a related note I seem to be unable to get javac to accept a -target option above 1.5/5:
$
/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/bin/javac
Test.java -verbose -extdirs . -endorseddirs . -cp . -bootclasspath
/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib/rt.jar
-version -target 1.7
results in:
javac 1.7.0_51
javac: invalid target release: 1.7
See Question&Answers more detail:
os