Without installing Ant-Contrib or similar Ant extensions, you can do what you want with the following XML:
<project default="echo-lib-path">
<property name="lib.dir" value="lib"/>
<property name="build.dir" value="build"/>
<available file="${build.dir}" type="dir" property="build.dir.exists"/>
<target name="-set-path-with-build-dir" if="build.dir.exists">
<echo message="Executed -set-path-with-build-dir"/>
<path id="lib.path.ref">
<fileset dir="${lib.dir}" includes="*.jar"/>
<path location="${build.dir}" />
</path>
</target>
<target name="-set-path-without-build-dir" unless="build.dir.exists">
<echo message="Executed -set-path-without-build-dir"/>
<path id="lib.path.ref">
<fileset dir="${lib.dir}" includes="*.jar"/>
</path>
</target>
<target name="-init" depends="-set-path-with-build-dir, -set-path-without-build-dir"/>
<target name="echo-lib-path" depends="-init">
<property name="lib.path.property" refid="lib.path.ref"/>
<echo message="${lib.path.property}"/>
</target>
</project>
The important part here is what happens in the target -init. It depends on the goals -set-path-with-build-dirand -set-path-without-build-dir, but Ant fulfills only one goal, based on whether it is installed build.dir.existsor not.
: http://ant.apache.org/manual/Tasks/available.html.