This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information

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:

JRE version less than 1.7 is not supported.

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:

//String path = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, new String("")); //$NON-NLS-1$
//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

Version: Mars Release (4.5.0)
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.

56 Responses to “Eclipse MARS with ANT and JRE 6 (story)”

  1. MattKay says:

    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 :(

  2. rjahn says:

    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.

  3. rjahn says:

    After an update to Mars SR1, the updated plugin should be used:
    ANT plugin Mars SR1

    Built for:

    Version: Mars.1 Release (4.5.1)
    Build id: 20150924-1200

    The tag-id of the ANT plugin source code: M20150826-1000.

  4. MattKay says:

    Thank you very much for your effort!
    Works like a charm!

  5. Nate R says:

    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.

  6. Ken H says:

    Another thanks for making this available!

  7. Jen says:

    Where is the plugin folder on mars eclipse?

  8. rjahn says:

    ?

    The plugins folder.

  9. Jen says:

    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 !

  10. rjahn says:

    The plugins folder is in the Eclipse installation folder. You should know where you stored/installed Eclipse. The same folder contains eclipse.exe

  11. Christian says:

    Thank you very much!

  12. Eder says:

    Amazing, thank you all for sharing.

  13. Brian says:

    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.

  14. Fabian says:

    Please open a new eclipse bug and offer your solution as a patch.

  15. rjahn says:

    When time permits.

  16. Dan Condon-Jones says:

    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?

  17. rjahn says:

    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.

  18. Dan Condon-Jones says:

    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!!!!!!!

  19. Mike Evans says:

    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!

  20. rjahn says:

    Thanks for your kind words :)

  21. Julius says:

    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?).

  22. Alex says:

    Could you please add a plugin for Eclipse 4.5.2?
    This would be so helpful for me!!!
    Many Thx!

  23. rjahn says:

    I still use Mars.1 and that's the reason why there's no plugin for Mars.2.

    I'll do my best :)

  24. rjahn says:

    After an update to Mars.2, the updated plugin should be used:
    ANT plugin Mars.2

    Built for:

    Version: Mars.2 Release (4.5.2)
    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).

  25. Julius says:

    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?

  26. rjahn says:

    What's the problem with above description?

  27. Julius says:

    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.

  28. rjahn says:

    1) Download Eclipse for RCP...
    2) Download plugin Source Code, extract, ...
    3) Import existing project
    4) configure Java6 (plugin.xml, ...)
    5) create jars

  29. Julius says:

    ah, i see!
    Thank you, i will try that. :)

  30. Jonathan says:

    Thank you very much, it worked very well!!! those plugins of yours rock!!!

  31. Bhavesh says:

    Thanks a lot for providing these JARs and updates.

  32. Kathryn says:

    Thank you so much!

  33. tharpa says:

    I successfully used the earlier plugin you created. However, the new one (for Mars.2) did not work for me for some reason.

  34. tharpa says:

    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.

  35. Mithlesh Singh says:

    Any Ant Changes for ?
    Version: Mars.2 (4.5.2)
    Build id: M20160212-1500

  36. rjahn says:

    Not yet.

  37. tharpa says:

    Any word on whether it will work for Neon?

  38. rjahn says:

    The jars won't work with Neon, but it won't be a problem to create a working plugin. We'll see...

  39. dennisk1718 says:

    You 'de man

  40. MikeR says:

    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. :(

  41. rjahn says:

    Do the version numbers of your Mars.1 match?

    Version: Mars.1 Release (4.5.1)
    Build id: 20150924-1200

    Did you start with -clean option once?

  42. MikeR says:

    yes I did start with -clean option and Mars.1 is 4.5.1 with same build id.

  43. rjahn says:

    Please try a fresh Eclipse installation with a fresh workspace. Did you use the installer version or the manual install version?

  44. Paul says:

    Any update with for Neon 4.6.2 Build Id: 20161208-0600?

  45. rjahn says:

    No, not planned.

  46. Paul says:

    You're all done supporting?

  47. rjahn says:

    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.

  48. Paul says:

    I got you...I'll rollback my update. Thanks for the response.

  49. camilo says:

    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.

Leave a Reply

Spam protection by WP Captcha-Free