Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
697 views
in Technique[技术] by (71.8m points)

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

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..uild.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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 FilesJavajdk1.x.xlib. Likewise if required add the JRE by pointing it to C:Program FilesJavajdk1.x.x


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...