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?!
- Screenshot: Choosing JDK 1.6 as Runtime JRE for ANT
- Screenshot: Error when executing ANT script
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:
List<MyObject> list = new ArrayList<>();
try (InputStream stream = createInputStream()) { ...}
Backwards compatibility for Diamond operator:
and for try-with-resources:
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:
More details about the solution can be found in this blog post.