Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UnsupportedClassVersionError when running Ant from eclipse

I'm trying to run an ant script from eclipse but it fails 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 command line (./ant) it runs as expected.
Environment info:

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

I've also set the "Ant Home" (within eclipse settings) to be the same as the one I use from command line.

I've searched a lot on this issue but I can't seem to find anything that helped, I can try to uninstall all java (jdk/jre) I currently have installed, and then reinstall java 7, but I prefer not to take this route.

Any ideas? Thanks!

like image 711
Nitzan Tomer Avatar asked Jan 29 '13 10:01

Nitzan Tomer


2 Answers

UnsupportedClassVersionError: com/sun/tools/javac/Main : Unsupported major.minor version 51.0

This suggests there's some mix up between versions - Ant is trying to run the Java 7 javac on a Java 6 JVM. Have a look at your project properties, builders, Ant Builder, and check the classpath section. On my Eclipse with a newly-created Ant Builder I have the tools.jar from my 1.7 JDK listed under user entries -> additional tasks and support. If you have the same, but your Eclipse is itself running on Java 6 then it won't work. You can find out which Java Eclipse itself is running on via the "about Eclipse" box under installation details -> configuration. This may not be the same as the version of Java that your project is configured to use.

Another thing that might fix it is to go to the JRE tab in the ant builder settings and tell it to run in a separate JRE rather than running within the Eclipse process.

like image 198
Ian Roberts Avatar answered Oct 06 '22 00:10

Ian Roberts


Your Eclipse ant task is trying to run the Java7 JDK compiler using a pre-Java7 JDK/JRE. Make sure you use a Java7 JRE to run Eclipse.

like image 41
Anders R. Bystrup Avatar answered Oct 05 '22 23:10

Anders R. Bystrup