When compiling code to another version other than the used javac sdk, you need to also set the -bootclasspath, otherwise you will still end up binging your .class files to the sdk version API classes of your javac. You wont get any issues at compile time, but you could at runtime.
To set this up in ant is straight forward. I like to set variables so if i ever need to change them it just the once.
<path id="bootclasspath.lib.path.ref">
<fileset dir="C:/j2sdk1.4.2_16/jre/lib" includes="*.jar" />
</path>
On your compile target, use the variable you have set via the compilearg option.
<target name="compile ">
<javac debug="true" deprecation="true" verbose="true" srcdir="${src.dir}" destdir="${bin.dir}" nowarn="false" source="1.4" target="1.4">
<compilerarg value="-Xbootclasspath/p:${toString:bootclasspath.lib.path.ref}"/>
<classpath>
<pathelement path="${eclipse.classpath}" />
</classpath>
</javac>
</target>
If you have verbose=”true” on the javac task you should see some output from ant similar to this when ant does the javac target
[javac] [loading C:/j2sdk1.4.2_16/jre/lib/rt.jar(java/io/IOException.class)]
[javac] [loading C:/j2sdk1.4.2_16/jre/lib/rt.jar(java/text/ParseException.class)]
[javac] [loading C:/j2sdk1.4.2_16/jre/lib/rt.jar(java/util/ArrayList.class)]
[javac] [loading C:/j2sdk1.4.2_16/jre/lib/rt.jar(java/util/List.class)]
[javac] [loading C:/j2sdk1.4.2_16/jre/lib/rt.jar(java/lang/String.class)]
[javac] [loading C:/j2sdk1.4.2_16/jre/lib/rt.jar(java/lang/StringBuffer.class)]