I have installed two jdks - jdk 1.5 and jdk 1.8. I have following Ant build.xml config file :
I tried all of the other solutions, but none worked. I finally found an approach that worked for me in Eclipse:
ant window.Run As | External Tool ConfigurationsJRE tab, choose Separate JRE: Java SE7 or whatever your java 7 is named, then hit Apply and then Run.Your ant task will be executed, and will build correctly!