Run Ant on Eclipse Mars with Java 1.6

☆樱花仙子☆ 提交于 2019-11-30 04:47:01

I faced the same problem after upgrading to Eclipse Mars.

I solved this by changing the runtime environment of the external tool configuration of the project to JDK7.

I assume you know how to add JDK7 to your installed jre in eclipse

Open External Tools Configurations... and then change the JRE to JDK 1.7

Then change the JRE

But this will create another problem, the compiled jar will be in JDK 7 and this will not work on production servers with JDK6.

To solve this, simply change the target attribute in the task to be 1.6

<javac target="1.6">

As per suggested from @dag and @Chris, Here is updated ant javac task.

rjahn

We fixed the problem for us using a patched Ant plugin. For Eclipse Neon, also see this link as is noted in the comments on the first page.

please take a look at the <javac>reference https://ant.apache.org/manual/Tasks/javac.html#compilervalues and add the following attributes to your <javac>-Task: compiler="javac1.6" source="1.6" target="1.6" executable="[path-to-jdk-1.6/bin/javac]" fork="true" taskname="javac1.6".

No you cannot go for JDK1.6 or less because Eclipse Mars only runs with Java >=1.7. Refer this link.

The Java you use to run Eclipse does not have to be the same as the one you use for your projects. You must run Eclipse Mars using Java 7 (or 8) but you can use Java 6 for your projects.

Tell Eclipse about Java 6 in the Preferences in 'Java > Installed JREs' and set that as the default (or select it in individual projects).

I have Eclipse Oxygen running on JRE 1.8 but building some old 1.7 projects, and have jdk1.7.0_40 installed as a separate JRE and set up in the tools external config, but still got the "jre less than 1.8 not supported" error.

What fixed it for me was just updating the build xml configuration directly, especially if you have another project which does work that you can copy from.

Specifically, I went to the launch configurations at:

workspace/.metadata/.plugins/org.eclipse.debug.core/.launches

And edited the relevant ...build.xml.launch file, replacing:

<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.7.0_40"/>

With:

<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_INSTALL_NAME" value="jdk1.7.0_40"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_INSTALL_TYPE_ID" value="org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType"/>

And restarted Eclipse to pick it up.

No idea if this is moving forward or backwards in terms of Eclipse support, but it fixed my problem.

I recently ran into this issue with Java 8 being on my machine, using Elicpse Oxygen and trying to use Ant to build a Java 6 project. I used some suggestions above but also encountered some strange behavior during the Ant build process. In the end it worked, here were my steps:

1) Java home ended up staying pointed to Java 8.

2) Set in the Ant script the values suggested by @Chris.

3) Do not change the Ant Runtime JRE, mine was left at 8, and in fact would not run the Ant build if I changed it to 6...

4) Project settings build path and compiler levels were all set to 6.

5) Run the build.

This produces a build at the Java 6 level that worked for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!