This post by Ilya Chemodanov explains the two solutions beautifully.
If you do not want to compile and import the Java class, you can do it in pure ant: (although these are pretty hacks)
<target name="get-cores">
<property environment="env"/>
<condition property="cores.count" value="${env.NUMBER_OF_PROCESSORS}">
<os family="windows" />
</condition>
<exec executable="nproc" outputproperty="cores.count" os="Linux,SunOS,Solaris">
<arg value="--all"/>
</exec>
<exec executable="sysctl" outputproperty="cores.count" os="Mac OS X">
<arg value="-n"/>
<arg value="hw.ncpu"/>
</exec>
<echo message="Number of cores: ${cores.count}"/>
</target>