Java – Eclipse Mars: ANT doesn’t support JDK 1.6 anymore

anteclipsejava

When I use JDK6 for calling an ANT script in Eclipse Mars (Run as > Ant Build … > JRE > Separate JRE), I get following error message:

Problem occured: JRE version less than 1.7 is not supported.

Is this only a bug or intentionally? I can't find a corresponding bug report at Eclipse. So Eclipse dropped Java 6 support for ANT?!

Best Answer

We fixed the problem with a custom ANT plugin. It's a replacement of the Mars bundled ANT plugin. The original plugin didn't support Java < 7 because it was written with Java 7 syntax and it had a check for Java version. It was easy to replace Java7 syntax to be compatible with >= 5 and to remove the Java 7 check.

The two syntax "problems" were:

  • Diamond operator, e.g. List<MyObject> list = new ArrayList<>();
  • try-with-resources, e.g. try (InputStream stream = createInputStream()) { ...}

Backwards compatibility for Diamond operator:

List<MyObject> list = new ArrayList<MyObject>();

and for try-with-resources:

InputStream stream;

try
{
  ...
}
finally
{
   stream.close();
}

After we replaced the bundled plugin with our custom plugin, it was possible to start an ANT task with a custom JRE, as usual.

It's possible to create your own ANT plugin with original sources from Eclipse git repository: http://git.eclipse.org/c/platform/eclipse.platform.git/refs/tags (use Tag ID: I20150430-1445) or to use my pre-compiled bundle: Eclipse Mars ANT plugin with support for Java < 7

Installation is easy:

  • Download the zip archive*, extract the content to <eclipse_dir>/plugins.
  • Start eclipse with parameter -clean (only once)
  • Configure JRE6 for your ANT task, via Externals Tool configuration...

More details about the solution can be found in this blog post.