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
After much playing around with the numerous discussions fixes posted - all of which didn't do the trick - I resorted to using dtrace to see what files were being accessed by javac when the command was run.
In terminal (you need XCode installed)
sudo dtrace -s /dev/stdin
syscall::open*:entry
{
printf("%s %s", execname, copyinstr(arg0));
}
<Ctrl-D>
The running the command line in another terminal instance I found buried in the file accessing activity for javac - which is pretty extensive considering the command line options give you the impression that you are restricting where it looks for files - I found
open:entry javac /Users/me/Library/Java/Extensions/tools.jar
I didn't realise I had a local extensions folder.....
Deleting the contents of it fixed the problem.
So, it is a version mismatch caused by old jars - as others have discovered - the problem in my case was finding them
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