I just changed jdk
from 1.6
to 1.8
and when making an new ant
build, it gives such error messages:
[javac] /usr/workspace/test/src/JsonString.java:7: cannot access java.lang.Object
[javac] bad class file: java/lang/Object.class(java/lang:Object.class)
[javac] class file has wrong version 52.0, should be 50.0
[javac] Please remove or make sure it appears in the correct subdirectory of the classpath.
[javac] public class JsonString {
[javac]
This is weird. the Object
class should be in java1.8
, how could it be bad? Do anyone know how to solve this?
First check that the
javac
task is not using a specific compiler other than the default one. This can occur if you're setting theexecutable
attribute to fork a specific compiler (along withfork="yes"
), as mentioned in the task documentation:If you're just calling
javac
without specifying any external compiler, then Ant would use the compiler that comes with the Java version that is running Ant. And from the error message, it's clearly using the Java 1.6 compiler (for which classfiles have version 50.0). Ant normally runs using thejava
executable found in thePATH
environment variable. So make sure that the first Java directory that is specified in thePATH
variable is Java 1.8.Ideally you should have
JAVA_HOME
set to the path of Java 1.8, and havePATH
refer toJAVA_HOME
itself so that both point to the same installation.