Eclipse MARS with ANT and JRE 6 (story)
Eclipse Mars is available since June 25th. We didn't update our IDEs because it wasn't needed.
Some days ago we played around with JavaFXPorts Eclipse plugin. This plugin requires Eclipse Mars. So far so good. We made some tests with Mars, and everything was fine. We installed all required plugins for our internal and customer projects and configured a first workspace....
After everything was done, we tried to work with Eclipse Mars - no problems... BUT we have many projects with Java 6 compatibility.
Why Java 6?
Some big legacy projects/applications and Oracle Forms compatibility. There are more reasons, but it's not unusual to be backwards compatible, especially for frameworks and libraries!
Long story, short: It's not possible to start an ANT task with Java 6, because Java 7 is required. A nice error message appears:
BUT it's still possible to choose any JRE in Runtime configuration dialog.
Why shouldn't it be possible to start ANT with "any" JRE?
We tried to find help in the world wide web and found some postings about our problem:
http://stackoverflow.com/questions/31052878/run-eclipse-mars-with-java-1-6
http://stackoverflow.com/questions/31808102/eclipse-mars-ant-doesnt-support-jdk-1-6-anymore
And two bug database entries:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=474386
https://bugs.eclipse.org/bugs/show_bug.cgi?id=461031
It's absolutely incomprehensible why the first ticket is in state: RESOLVED INVALID and the
second one: VERIFIED FIXED.
OK, the second one was for a different requirement, but the first one explains the problem.
Why did the developer ignore the user requirement?
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 building our software!
I can't live with recommended workarounds because suggested steps were not usuable with big projects!
So, we tried to solve the problem for us. The source code of the ANT plugin is available here, so it shouldn't be a problem to "fix" the problem.
After reading source code, we found that the only reason why it's not possible to use JREs < version 7, is Java 7 Syntax:
- Diamond operator, e.g. List<MyObject> list = new ArrayList<>();
- try-with-resources, e.g. try (InputStream stream = createInputStream()) { ...}
And of course, the plugin was configured for execution environment JavaSE-1.7.
Our solution: Removed Java version check in class org.eclipse.ant.internal.launching.launchConfigurations.AntLaunchDelegate, method launch:
//if (!path.isEmpty()) {
// IPath jrePath = Path.fromPortableString(path);
// IVMInstall vm = JavaRuntime.getVMInstall(jrePath);
// if (vm instanceof AbstractVMInstall) {
// AbstractVMInstall install = (AbstractVMInstall) vm;
// String vmver = install.getJavaVersion();
// // versionToJdkLevel only handles 3 char versions = 1.5, 1.6, 1.9, etc
// if (vmver.length() > 3) {
// vmver = vmver.substring(0, 3);
// }
// int ver = (int) (CompilerOptions.versionToJdkLevel(vmver) >>> 16);
// if (ver < ClassFileConstants.MAJOR_VERSION_1_7) {
// // IStatus status = new Status(IStatus.ERROR, AntLaunching.PLUGIN_ID, 1,
// // AntLaunchConfigurationMessages.AntLaunchDelegate_Launching__0__2, null);
// // throw new CoreException(status);
// }
// }
//}
We set the execution environment for org.eclipse.ant.launching, org.eclipse.ant.core and org.eclipse.ant.ui to JavaSE-1.6 and made the source code compatible with Java 6 syntax.
After we built the required jar files, we had problems with Eclipse, because there was something like a plugin cache (not sure what exactly). We made a test with -clean command line parameter and were happy. 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
Build id: 20150621-1200
The tag-id of the ANT plugin source code: I20150430-1445.
Installation?
- 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...
Feel free to use our changed files but we don't guarantee that it doesn't destroy your Eclipse Mars installation
We didn't have any problems so far, but send us your impressions.
We didn't publish the changed source code right now, but let us know if you need it - it's still under EPL.
Hi! Thanks for this solution! It works really fine for Eclipse 4.5.0. But I just updated to 4.5.1, recopied the jars, started with clean parameter again but the fix does not work anymore
Clear, because 4.5.1 version is not compatible with 4.5.0 version of ANT integration (API changes, ...). I didn't update my Eclipse installation, but it's not a problem to create the plugin for 4.5.1 with above steps.
After an update to Mars SR1, the updated plugin should be used:
ANT plugin Mars SR1
Built for:
Build id: 20150924-1200
The tag-id of the ANT plugin source code: M20150826-1000.
Thank you very much for your effort!
Works like a charm!
Thank you for this awesome fix. Our Organization is stuck with java 1.5 app servers, with a similar requirement. This fix saved me a bunch of time tracking it down.
Another thanks for making this available!
Where is the plugin folder on mars eclipse?
?
The plugins folder.
Yes, I couldn't find it....I just found under C:\Users\Myname\p2\.... a plugins folder where I dropped the the jar and followed the steps and the old ant works !
The plugins folder is in the Eclipse installation folder. You should know where you stored/installed Eclipse. The same folder contains eclipse.exe
Thank you very much!
Amazing, thank you all for sharing.
I'm very glad to have found this. I initially missed the installation step of a one time startup of eclipse with -clean and encountered a main class not found error when running an ant task. Once I did as instructed, though, its working great, and I don't have to deal with organization-wide build machine changes and source changes for JAXB xjc code generation differences with JRE7 and above.
Please open a new eclipse bug and offer your solution as a patch.
When time permits.
I'm trying to get this to work, but so far no joy.
There isn't a 'plugins' folder in my Eclipse installation folder. There is however, an 'dropins' folder. There is also a .p2\pool\plugins folder. I've tried both of these - and I've also tried creating a plugins folder in my Eclipse folder and using that. Whatever I do I still get the error when I set my Runtime JRE to Jedi 1.6.0_45.
Does anyone know what I'm doing wrong?
Not sure which Eclipse package you have, but you could try to download e.g. Eclipse IDE for Java EE Developers (https://eclipse.org/downloads/), and check the archive content. All "my" Eclipse installations have the plugins folder.
Ah - I did two things wrong.
1 - I used the Eclipse installer which shoves the plugins folder somewhere else.
2 - I stick the unzipped folder in the plugins folder rather than just the files.
Sorted now. I have spent a week in hell, and have grown to hate Eclipse with every fibre of my being - but I have just managed to get the thing to build successfully!
Thanks hugely!!!!!!!
Thank you, thank you, thank you, thank you!
Thank you for finding this problem
Thank you for finding a solution to the problem
Thank you for sharing your solution
And thanks for such a good explanation to go with it!
Thanks for your kind words
Hi!
Thank you very much for this solution from me too. I was very happy when i found this.
Could you maybe provide a package for Eclipse Mars.2?
I tried to do it myself, but i never developed any Eclipse plugins and i don't even know how to start (do i need an Eclipse SDK?).
Could you please add a plugin for Eclipse 4.5.2?
This would be so helpful for me!!!
Many Thx!
I still use Mars.1 and that's the reason why there's no plugin for Mars.2.
I'll do my best
After an update to Mars.2, the updated plugin should be used:
ANT plugin Mars.2
Built for:
Build id: 20160218-0600
The tag-id of the ANT plugin source code: M20160203-1000.
To avoid problems, start Eclipse once with -clean (e.g. eclipse.ini).
Thanks a lot!
Still i would be curious how to do that myself. Can you give me a few hints on how to build the ANT plugin?
What's the problem with above description?
Like i said, i don't know how to start. I've never built plugins.
Do i need an Eclipse SDK? I tried importing the ANT project into my Eclipse, but it threw a whole bunch of errors, that he couldn't find needed packages.
1) Download Eclipse for RCP...
2) Download plugin Source Code, extract, ...
3) Import existing project
4) configure Java6 (plugin.xml, ...)
5) create jars
ah, i see!
Thank you, i will try that.
Thank you very much, it worked very well!!! those plugins of yours rock!!!
Thanks a lot for providing these JARs and updates.
Thank you so much!
I successfully used the earlier plugin you created. However, the new one (for Mars.2) did not work for me for some reason.
Addendum to my last comment: Resolved. I was looking in the plugin folder from where the application is launched. However, I needed to make the change in the working directory as listed on the JRE tab of the Edit Configuration window of the Ant file I was trying to run.
Any Ant Changes for ?
Version: Mars.2 (4.5.2)
Build id: M20160212-1500
Not yet.
Any word on whether it will work for Neon?
The jars won't work with Neon, but it won't be a problem to create a working plugin. We'll see...
Support for NEON (4.6.0)
You 'de man
Thanks for sharing this...
but I have applied this into my Mars.1, but still getting the same error message. I'm pretty sure I did not miss a step.
Do the version numbers of your Mars.1 match?
Build id: 20150924-1200
Did you start with -clean option once?
yes I did start with -clean option and Mars.1 is 4.5.1 with same build id.
Please try a fresh Eclipse installation with a fresh workspace. Did you use the installer version or the manual install version?
Any update with for Neon 4.6.2 Build Id: 20161208-0600?
No, not planned.
You're all done supporting?
It needs some hours to create a backwards compatible plugin... but I don't need it and only some users will use it, so it's not worth the time.
I got you...I'll rollback my update. Thanks for the response.
I'm passing through difficult times trying to make this patch to work on my Eclipse Neon 3 ee. I need urgently to enable it to run my ant launchers for JRE 1.6. Any help would be highly appreciated.