You can register the Dimensions Ant task with a definition similar to the following:
<taskdef name="dimensions" classname="com.serena.dmtpi.DimensionsTask">
<classpath>
<fileset dir="${DM_ROOT}/java_api/lib">
<include name="*.jar"/>
</fileset>
</classpath>
</taskdef>
where you have set the Ant DM_ROOT property to an appropriate value elsewhere in the script.
For more information see the documentation for the Ant <taskdef> task on the Apache Ant web site.