22

I downloaded the latest release of Eclipse (Mars) and changed the required Java version to 1.6 in eclipse.ini file as my project uses Java 1.6.

I configured installed JREs inside Eclipse to use Java 1.6. But when I try to execute my ant target it creates an error:

JRE version less than 1.7 is not supported.

Is there any workaround to use Java 1.6 in Mars version as I'm unable to upgrade to Java 1.7 at the moment?

Paolo Forgia
  • 6,572
  • 8
  • 46
  • 58
  • 7
    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 using Java 7 (or 8) but can use Java 6 for your projects. – greg-449 Jun 25 '15 at 14:24
  • A similar problem was discussed in this stackoverflow question: http://stackoverflow.com/questions/31808102/eclipse-mars-ant-doesnt-support-jdk-1-6-anymore/ – rjahn Sep 29 '15 at 14:48

9 Answers9

22

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

Open External Tools Configurations

Then change the JRE

Change 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">

Change Task target to 1.6

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

Amr Eladawy
  • 4,193
  • 7
  • 34
  • 52
  • After all this is still not exactly the same as compiling the code with a "native" 1.6 JDK, therefore you need to add the `executable` attribute as Chris suggested. – dag Jul 17 '15 at 08:03
  • This is a good sugesstion, Can I update my answer to add the ant attribute from @Chris answer? I think my answer covers two sides, running Ant with JRE7 (unlink the JRE used for eclipse) and solving the issue of the generated byte code version. – Amr Eladawy Jul 18 '15 at 09:01
  • @AmrElAdawy: Dear, I've followed your precious advice but my problem remains ;( (My scenario is STS 4.1, jdk 8 but I want to compile with JDK 7 with Ant). In MANIFEST.MF file what I must find in "Created-By: " info jdk 1.8 or jdk 1.7? – Joe Taras Jan 14 '19 at 08:49
6

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.

Asclepius
  • 57,944
  • 17
  • 167
  • 143
rjahn
  • 438
  • 4
  • 8
  • 3
    Note that [link-only answers](http://meta.stackoverflow.com/tags/link-only-answers/info) are discouraged, SO answers should be the end-point of a search for a solution (vs. yet another stopover of references, which tend to get stale over time). Please consider adding a stand-alone synopsis here, keeping the link as a reference – kleopatra Sep 26 '15 at 10:00
5

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

Joand
  • 330
  • 4
  • 13
5

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.

Barney
  • 2,786
  • 2
  • 32
  • 34
3

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

Badal
  • 376
  • 4
  • 11
  • 2
    The better reference for Eclipse's requirements is https://www.eclipse.org/downloads/ - see under **Hint**. But why on earth would a developer need to use an EOL'ed JVM to run his/her IDE? Even when running Eclipse on Java 8 you can still develop software *for* Java 6 (see greg-449's answer). – Stephan Herrmann Jun 29 '15 at 22:17
  • Its all about version,release and the platform which they are going to support. – Badal Jun 30 '15 at 04:44
  • 4
    "why on earth would a developer need to use" - because we work for big companies with lots of legacy applications. And every change has to go thro proper engg change control. – Blessed Geek Nov 12 '15 at 23:43
  • @BlessedGeek am facing the same issue now. – divine Apr 07 '16 at 07:27
2

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

greg-449
  • 109,219
  • 232
  • 102
  • 145
  • I did set 1.6 version in installed JREs, but it does not work when trying to execute the ant target through Eclipse – Chandika Gunawardhana Jun 25 '15 at 16:42
  • ant target to compile and deploy my project in build.xml – Chandika Gunawardhana Jun 25 '15 at 17:35
  • 2
    I think this is a bug. I experienced that today too. Using Eclipse with JDK 8, Projects are compiled for JDK 6, wich is no problem at all. But when trying to run ant (as external tool configuration) in a JDK 6 (i also changed the ant runtime to a external one) the described error message is shown. – dag Jul 17 '15 at 08:02
1

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.

Adam
  • 490
  • 7
  • 21
0

Solution for me was to download an ant version compatible with JRE 6/7 and change in the "External Tool Configuration" the Ant Home Path to match the one I downloaded (ClassPath > Ant Home")

enter image description here

-2

add new JRE version bigger than 1.7

harun ugur
  • 1,718
  • 18
  • 18