Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Ant giving me a Unsupported major.minor version error

Tags:

java

eclipse

ant

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.

enter image description here

Please help me resolve it.

like image 321
coder Avatar asked Aug 16 '11 03:08

coder


People also ask

What is unsupported class version error?

The UnsupportedClassVersionError is a sub-class of the LinkageError and thrown by the Java Virtual Machine (JVM). When a class file is read and when major and minor version numbers are not supported, this error is thrown, and especially during the linking phase, this error is thrown.

What is major minor version in Java?

minor version error is thrown in Java when a class is compiled using a higher version of the Java Development Kit (JDK) but executed on a lower version of the Java Runtime Environment (JRE). The exact cause is printed on the version e.g. in the case of major.


1 Answers

Check if tools.jar used during compilation complies with the JRE set. If you are on eclipse, verify the versions as:
Goto Window->Preferences
- Check Ant Runtime by selecting Runtime under Ant in the left pane. Check the Global Entries under classpath tab. You can see the version in folder path.
- On the left pane check installed JREs under Java. Check the version.
I had also got the same problem when my selected JRE was 1.6.0_24 and tools.jar in Ant runtime was coming from jdk 1.7 If both of them are from different versions- 1.6/1.7, correct them by correcting their path. Typically, tools.jar can be found at :C:\Program Files\Java\jdk1.x.x\lib. Likewise if required add the JRE by pointing it to C:\Program Files\Java\jdk1.x.x\

like image 93
abksrv Avatar answered Oct 02 '22 06:10

abksrv