Thursday, January 4, 2018

Ant Build Problem in Eclipse Oxygen - JRE less than 1.8 is not supported

When executing ant build within Eclipse using JRE 1.6, the following error occurs:



One would ask, "Why use old JRE when there are newer and better versions?"

The answer to this question is, in some environments, there are existing legacy system that cannot be upgraded due to various reasons including financial constraints.
The Eclipse Oxygen comes with Ant version 1.10.1 plugin. Apache Ant 1.10.x requires Java Runtime 1.8, whereas Ant 1.9.x stays compatible with Java 1.5 to 1.7.

Since Ant 1.10.x requires JRE8 and above, if you run an ant build file using the default Ant Home that points to the ant plugin, the ant launcher checks for the JRE version and prevent ant from launching with older JRE. However, if you configure to run your ant build with an external Ant runtime (configure Ant Home in the classpath to point to the external Ant 1.9.x runtime), it does not block ant runtime from launching.

Below is the source code of the ant launching method in org\eclipse\ant\internal\launching\launchConfigurations\AntLauchDelegate.java 


First download Apache Ant 1.9.9 and extract it. Then, configure external ant runtime in the ant build launcher and change the Ant Home in the Classpath tab.








That's it. Now the ant build file can be executed in Eclipse with JRE6.

12 comments:

  1. Hi, I have a same problem and Your method helped for me.

    But after same upgrade of Oxygen this fix not work.

    I found another solution https://stackoverflow.com/questions/45785949/eclipse-oxygen-upgrade-java-virtual-machine-launcher-a-java-exception-has-o

    In my eclipse envronment I must add only one jar to list:
    eclipse\configuration\org.eclipse.osgi\1088\0\.cp\ant_tasks\resources-ant.jar

    After that Ant 1.9 with java 1.7 works again.

    ReplyDelete
    Replies
    1. My God!!!
      Thanks to you, i can fix my problem!
      Really Thank you~!!!

      Delete
  2. Hi, it's really helpful!!!
    Thanks a lot!
    Before this, I've tried lots of ways, but no one could work.

    ReplyDelete
  3. Hi I follow the same steps but still i having the same issue. can u help me how can iresolve it

    ReplyDelete
    Replies
    1. You might be launching old launch configuration files.

      Check under the folder workspace\.metadata\.plugins\org.eclipse.debug.core\.launches

      Make sure there is only one configuration file for each ant build xml file. If you see multiple configuration files, they look like ant-build.xml(1).launch, ant-build.xml(2).launch, etc. Delete the old launch files, then reconfigure using the Ant External Tools Configuration menu. The ant build launch file will be recreated.

      Run "eclipse -clean", then delete the duplicate launch files inside Eclipse. Ant->Run As->Select External Tools Configuration, then on the left hand pane, right-click on the ant build configuration->Delete. Double check the launch configuration physical file is deleted.

      Then, reconfigure ant launch. Hope this helps.

      Delete
  4. Been searching for such a remarkable blog like this for a long time.
    top-10-best-ant-killers

    ReplyDelete
  5. Thank you, Thank you, it absolutely helped me.

    ReplyDelete