UnsupportedClassVersionError when running Ant from eclipse

I am trying to run ant script from eclipse, but it does not work with the following message:

BUILD FAILED
project_path/build.xml:5:
java.lang.UnsupportedClassVersionError: com/sun/tools/javac/Main :
Unsupported major.minor version 51.0

However, when I run this from the command line (./ant), it works as expected.
Environment Information:

  • OS: Linux Mint 64
  • Eclipse: Juno (4.2.1)
  • JDK: Oracle 1.7.0_11
  • Ant (command line): 1.8.2

I also set "Ant Home" (in the eclipse settings) the same as the one I use from the command line.

I searched this problem a lot, but I can not find anything that helped, I can try to remove all java (jdk / jre) that I installed now, and then reinstall java 7, but I prefer not to follow this route.

Any ideas? Thank!

+5
source share
3

UnsupportedClassVersionError: com/sun/tools/javac/: major.minor 51.0

, - Ant Java 7 javac Java 6 JVM. , , Ant Builder . Eclipse Builder Ant tools.jar 1,7 JDK, → . , Eclipse Java 6, . , Java Eclipse "about Eclipse" " " → "". , Java, .

, , - JRE Ant , JRE, Eclipse.

+11

Eclipse ant J7K- Java7 J7K/JRE Java7. , Java7 JRE Eclipse.

+1

usually, if you compile a Java program in Java 1.7, it will create a class file with the main version 51.0, and if you run this in the lower version of java, you will get

 java.lang.unsupportedclassversionerror unsupported major.minor version 51.0

check this article for more details on the same

0
source

All Articles