Run Ant on Eclipse Mars with Java 1.6

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?

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.

474386 – Eclipse Mars: ANT doesn't support JDK 1.6 anymore?, Created attachment 255660 [details] Change Runtime JRE for ANT to JDK 1.6 When I use JDK6 for calling an ANT script in Eclipse Mars (Run as > Ant Build . 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?

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.

How to change JRE for Ant in Eclipse, How to specify a specific JRE version for running Ant build files in Eclipse IDE. In Eclipse IDE, Ant build script is executed under the same JRE of the again, and we will see Ant is executed under the new selected JRE 6:. It was possible to start ANT tasks - with JRE 6 - without modifications, directly via Eclipse. It's not difficult to create your own ANT plugin, but here are our jar files. The libs were built for

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

Eclipse MARS with ANT and JRE 6 (story) « Blog @ SIB Visions, It's possible to call ANT with "any" JRE, without Eclipse and other IDEs don't have such crazy limitations! We didn't plan to use another IDE just for  You are trying to run your program as ant build which is wrong. See Eclipse Doc: Running your programs. Use Right click on your source file and choose Run As-> Java Application or. Select "Run -> Run Configurations" from the menu. Search for you project in the list on the left and select it.

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.

Building Java Application with Ant and Eclipse Example, On successful installation, executing ant -version command shows output like : Figure 6 : Sample ANT Build File View in Eclipse Mars. Figure  If you want to run code that is compiled for a specific version of Java you need to have a runtime for that version of Java or a later version. So you can compile for version 1.4 and run that code using a JRE version 1.4 or 1.5 or 1.6 or 1.7 or 1.8 . This is what I was looking for.

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

Eclipse Mars: ANT doesn't support JDK 1.6 anymore?, When I use JDK6 for calling an ANT script in Eclipse Mars (Run as > Ant Build > JRE > Separate JRE), I get following error message:. It's been a long time since I worked with Ant, so I don't know why it's complaining about 1.6, but you can just change that configuration to use 1.7 or 1.8. That is just configuring which JVM is used to execute Ant (which is a Java program, after all) and should not impact your application.

Ant - Eclipse Integration, Eclipse comes pre bundled with the Ant plugin, ready to use. Make sure that the build.xml is a part of your java project, and does not reside at a location that is​  Eclipse IDE for Java EE Developers Package Description Tools for Java developers creating JEE and Web applications, including a Java IDE, tools for JEE and JSF, Mylyn and others.

Installing Apache Ant, Optionally, from the ANT_HOME directory run ant -f fetch.xml -Ddest=system to get the library All the main Java IDEs ship with Ant, products such as Eclipse, NetBeans and IntelliJ IDEA. If you install works with JDK 1.3 and higher, Ant 1.6. Select Ant branch, then check the option “Always run new Ant configurations in the same JRE as the workspace”. Related Tutorials: How to create Ant build file for existing Java project in Eclipse; Add custom Ant build script to Eclipse project . Other Eclipse Tutorials: How to use Eclipse IDE for Java EE Developers

Eclipse (software), Eclipse is an integrated development environment (IDE) used in computer programming. It contains a base workspace and an extensible plug-in system for customizing the environment. Eclipse is written mostly in Java and its primary use is for developing Java Kepler, Luna, and Mars continued the astronomy theme, and then Neon and  The Eclipse Foundation - home to a global community, the Eclipse IDE, Jakarta EE and over 350 open source projects, including runtimes, tools and frameworks.

Comments
  • 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.
  • A similar problem was discussed in this stackoverflow question: stackoverflow.com/questions/31808102/…
  • 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.
  • 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.
  • @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?
  • Note that link-only answers 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
  • The better reference for Eclipse's requirements is 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).
  • Its all about version,release and the platform which they are going to support.
  • "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.
  • @BlessedGeek am facing the same issue now.
  • I did set 1.6 version in installed JREs, but it does not work when trying to execute the ant target through Eclipse
  • ant target to compile and deploy my project in build.xml
  • 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.
  • Worked for me when I changed Ant Runtime JRE to the same JRE used by eclipse, as you pointed in step 3.