Why is Ant giving me a Unsupported major.minor ver

2019-01-06 17:32发布

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.

标签: java eclipse ant
12条回答
够拽才男人
2楼-- · 2019-01-06 18:16

I'd like to add my results here to help others, as while relevant, none of these solved my problem.
I had the unique situation where I went from workshop for weblogic 9.2 to Helios with JDK6. However our security experts pushed us on to JDK7, which forced my hand to go to Indigo.

In the end I used sysinternals process explorer to find if anything was currently using the JDK6 folder that still existed on my system. Sure enough it was Eclipse. I opened up eclipse.ini and the second line was referencing the JDK6, I replaced this with the JDK7 directory, started Eclipse, and the build was successful.

查看更多
戒情不戒烟
3楼-- · 2019-01-06 18:18

The runtime jre was set to jre 6 instead of jre 7 in the build configuration window.

查看更多
家丑人穷心不美
4楼-- · 2019-01-06 18:18
  1. Check whether u have jdk installed in the path "C:\Program Files\Java" If not Install the JDK in your machine

  2. In Eclipse, right click on "build.xml" then select Run As > External Tools Configuration

  3. Click on "JRE" tab then click on "Installed JREs" > "ADD" > "Standard VM" > Click "Next

  4. Select the Directory "C:\Program Files\Java\jdk1.7.x_xx" and the directory will be added to the "installed jres"

  5. Select the new JDK directory and Click "OK"

  6. Click on "Seperate JRE" dropdown and select the JDK version "jdk1.7.x_xx" and click on "Run"

This would help:)

查看更多
ゆ 、 Hurt°
5楼-- · 2019-01-06 18:21

Download the JDK version of the JRE to the installed JRE's and use that instead.
In Eclipse Indigo, if you check the classpath tab on the run configuration for ant, you will see that it defaults to adding the tools.jar from the system. So if you launch Eclipse using Java7 and run an ant build using a separate JRE6 it generates an UnsupportedClassVersionError. When I added the JDK version Eclipse picked up the tools.jar from the JDK and my ant task ran successfully.

查看更多
我只想做你的唯一
6楼-- · 2019-01-06 18:29

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\

查看更多
Luminary・发光体
7楼-- · 2019-01-06 18:29

go to run option--->select external tool option ---->external tool configuration---> select ant build ----> select your build.xml --->there you will find JDK option--->select your required JRE.

查看更多
登录 后发表回答