I'm running this target in Ant.
<target name="compile" depends="init"
description="compile the source " >
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}"/>
</target>
It's giving me this error.
C:\Users\..\workspace\..\build.xml:21: java.lang.UnsupportedClassVersionError: com/sun/tools/javac/Main : Unsupported major.minor version 51.0
Here are the versions:
Apache Ant(TM) version 1.8.2
JDK version is JDK 1.7.0
Here's my Compiler settings in Eclipse.
Please help me resolve it.
Simply just check your run time by go to ant build configuration and change the jre against to jdk (if jdk 1.7 then jre should be 1.7) .
enter image description here
One possible cause of this is an incorrect JRE selected in the Ant build options. After right-clicking the build.xml and choosing 'Run As...' and then 'Ant Build...', make sure the correct JRE is chosen under the JRE Tab of the configuration options dialogue box. You will see a 'Separate JRE' option; make sure the appropriate jdk is chosen from the drop down before clicking 'Run'.
If you're getting this error because you're purposefully trying to build to Java 6, but you have Java 7 elsewhere in Eclipse, then it may be because you are referencing a Java 7
tools.jar
in a Java 6 environment.You'll need to install the JDK 6 (not JRE) and add the JRE 6
tools.jar
as a User Entry in the Classpath of the build configuration, listed above the JRE 7tools.jar
.In my case, the project was a Maven, I had JDK 1.8.0, Eclipse : Kepler, and I installed the M2Eclipse plugin from Eclipse Marketplace.
Changing compiler level didn't help.
Finally I used latest version of eclipse (Luna), compiler level 1.7, same M2Eclipse plugin and problem was solved.
I run into the same problem. Then I went into Run as -> Ant build...->jre. I found the jre used is separate JRE which is the default eclipse JRE(1.6). Then I went to the perferences ->installed JREs . And change the location of the default eclipse JRE to my jdk(1.7).
The problem is resolved.
You would need to say which version of Ant and which JVM version.
You can run
ant -v
to see which settings Ant is using as per the docAnt 1.8* requires JDK 1.4 or higher.
The 'Unsupported major.minor version 51.0' means somewhere code was compiled for a version of the JDK, and that you are trying to run those classes under an older version of the JDK. (see here)