Question

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!

Was it helpful?

Solution

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.

OTHER TIPS

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.

generally if you compile Java program in Java 1.7 it will create class file with major version 51.0 and if you run that on lower java version you will get

 java.lang.unsupportedclassversionerror unsupported major.minor version 51.0

check this post for more details on the same

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top