I\'m using Ant 1.7.0 and installed java 1.6 which is in JAVA_HOME.
I want to build a project using java 1.5, so I\'ve exported JAVA_HOME to be my java 1.5 directory.
This is rather an old question, but I will add my notes for future references.
I had a similar issue and fixed it by changing the order of the exports in the PATH variable.
For example I was using a method of concatenating strings to my PATH by doing (this is just an example):
$> export PATH='$PATH:'$JAVA_HOME
If my variable PATH already had a java in it, the last value would be meaningless, thus the order would matter. To solve this I started inverting it by adding my variable first, then adding the PATH.
Following this idea I inverted the order that ANT_HOME was being exported. Adding JAVA_HOME before ANT_HOME.
This could be just a coincidence, but it worked for me.