I found the simple solution for this issue is to ensure that the JAVA_HOME variable points to the JDK or JRE, and most importantly, ensure that the tools.jar is included in the Ant classpath (Windows->Preferences->External Tools->Ant->Classpath tab.
Then, everything worked fine in Ant 1.4.1 and Ant 1.5.1 with any JDK I used.