I define <path> elements for each target.
This is an excerpt from my build file, you will have to adapt some paths and properties, but you can get the idea:
<path id="src.path"> <pathelement path="src/"/> </path> <path id="compile.path"> <path refid="src.path"/> <fileset dir="lib/"> <include name="**/*.jar"/> </fileset> </path> <path id="unit.test.path"> <path refid="compile.path"/> <pathelement path="test/"/> </path> <target name="compile"> <javac destdir="bin"> <src path="src"/> <classpath refid="compile.path"/> </javac> </target> <target name="compileUnitTests" depends="compile"> <javac srcdir="test/" destdir="bin"> <classpath refid="unit.test.path"/> </javac> </target> <target name="runUnitTests" depends="compileUnitTests"> <junit printsummary="yes" haltonfailure="no"> <jvmarg value="-Dfile.encoding=UTF-8"/> <classpath refid="unit.test.path"/> <formatter type="xml"/> <batchtest fork="yes" todir="${this.report}"> <fileset dir="test"> <include name="${test.pattern}"/> <exclude name="**/AllTests.class"/> <exclude name="**/*$*.class"/> </fileset> </batchtest> </junit> </target>
And if you need to clarify this for your needs, as cotton says, go read the ant task documents. Using ant with your specific directory structure requires some knowledge of this tool, don't expect you to easily find ready-made examples that just work with your exact requirements.
source share