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
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.
This is just plain stupidity. We also either have to switch back to older version of eclipse or switch to other IDE. Legacy systems still run in 1.6 and when you can create project with 1.6 jre in Mars,ant should also be able to compile it natively against 1.6.
The other solution is to update your build.xml where ever you call javac. In a corporate build it would be 100s of places.
Seems every eclipse version screws up some basic things.
Eclipse Mars dropped support for Java 6 :(
So we have to change to IntelliJ IDEA.
See:
There's something rather messed up about this!? My (Windows 7) environment is like this:
In this configuration, one "solution"(!) to this problem is to run the build file using the keyboard shortcut (or RMC->Run as->Ant Build), without any customization in the "External Tools Configuration" dialogs!?
The build file works fine when I use the keyborard shortcut (Alt-Shift-X, Q), (and it does start
javaw
, andjavac
from JDK 1.6 as I've observed from Process Explorer), but once I do a modification to the "launch configuration" (say choose a new target for example), then I also start getting the "JRE version less than 1.7 is not supported" error!?If, after getting the error, I go "External Tools Configuration..." -> "Delete selected launch configuration(s)", and start the build with the keyboard shortcut, it works again!?
Apparently the "JDK must be >= 1.7" check (of the default ant plug-in) mentioned by @rjahn above doesn't always get executed, but I haven't debugged it all the way to see why...
Java 1.7 required to launch ant build environment, but you can compile class files with any JDK. By default ant using javac and javaw from launch environment, but you can override it within ant tasks.
I used the following constants in the examples:
Java compilation: You can define javac location parameter named "executable":
After this, ant use javac to compile class files from JDK 1.6.
To run application from ant, with java 1.6, use jvm argument for java task:
Some ant task use the default compiler by default, for example the wsimport-ant task (it's generate source files from wsdl and compile it, with default java). To prevent this, run wsimport with -Xnocompile argument, and compile generated source files with javac (see above).
This methods work flawlessly in latest eclipse (Neon .3) with Oracle JDK 1.6 (or any other JDK).
Java 6 and 7 no longer receive public updates from Oracle. While you're fine compiling against the runtime libraries from older versions to suit those requirements, you should use a newer JRE to actually run anything.