Ant笔记
Ant是一个在Java开发里面很传说的一个工具,以前一直听说,却没有‘时间’去进行了解,最近借着读书的机会,好好了解了一番,发现ant在管理整个项目生命周期中,能起到相当大的自由度,比起严重的IDE以来,自由了许多,而且良好的自解释的XML格式,也很容易理解。虽然还是偏向maven一些,不过还是可以多了解一些。以后也可以去了解下make
<?xml version="1.0" ?><project name="tax-calculator" default="package"> <property name="src.dir" location="src"/> <property name="build.dir" location="build"/> <property name="tests.dir" location="test"/> <property name="build.classes.dir" location="${build.dir}/classes"/> <property name="test.classes.dir" location="${build.dir}/test-classes"/> <property name="lib" location="lib"/> <property name="dist.dir" location="dist"/> <property name="reports.dir" location="reports"/> <property name="reports.data.dir" location="reports/xml"/> <property name="reports.html.dir" location="reports/html"/> <property name="reports.javadoc" location="javadoc"/> <path id="compile.classpath"> <fileset dir="${lib}" includes="*.jar"/> </path> <path id="test.compile.classpath"> <path refid="compile.classpath"/> <pathelement location="${build.classes.dir}"/> </path> <path id="test.classpath"> <path refid="test.compile.classpath"/> <pathelement path="${test.classes.dir}"/> </path><target name="init"><mkdir dir="${build.classes.dir}"/><mkdir dir="${test.classes.dir}"/><mkdir dir="${dist.dir}"/> <mkdir dir="${tests.dir}"/> <mkdir dir="${reports.dir}"/> <mkdir dir="${reports.data.dir}"/> <mkdir dir="${reports.html.dir}"/> <mkdir dir="${reports.javadoc}"/></target><target name="compile" depends="init" description="Compile Java code"><javac srcdir="${src.dir}" destdir="${build.classes.dir}" classpathref="compile.classpath"/></target> <target name="compile-tests" depends="compile" description="Compile Unit Tests"><javac srcdir="${src.dir}" destdir="${test.classes.dir}" classpathref="test.compile.classpath"/></target><target name="package" depends="compile" description="Generate JAR file"><jar destfile="dist/tax-calculator.jar" basedir="build/classes"><manifest> <attribute name="Main-class" value="com.javapowertools.taxcalculator.Main"/></manifest></jar></target><target name="clean" depends="init" description="Deletes generated directories"><delete dir="build"/><delete dir="dist"/></target> <target name="test" depends="compile-tests" description="Run unit tests"> <junit printsummary="true" haltonfailure="true"> <classpath refid="test.classpath"/> <formatter type="plain" usefile="false"/> <formatter type="xml"/> <batchtest todir="${reports.dir}"> <fileset dir="${test.classes.dir}" includes="**/*Test.class"/> </batchtest> </junit> </target> <target name="test-report" depends="test" description="Generate HTML unit test report"> <junitreport todir="${reports.data.dir}"> <fileset dir="${reports.dir}"> <include name="TEST-*.xml"/> </fileset> <report format="frames" todir="${reports.html.dir}"/> </junitreport> </target> <target name="javadoc" depends="compile,init" description="Generate JavaDoc"> <javadoc sourcepath="${src.dir}" destdir="${reports.javadoc}" author="true" version="true" use="true" access="private" linksource="true" windowtitle="${ant.project.name} API"> <classpath > <path refid="compile.classpath"/> <pathelement path="${build.classes.dir}"/> </classpath> <doctitle ><![CDATA[<h1>${ant.project.name}</h1>]]></doctitle> <bottom ><![CDATA[<i>Copyright © 2007</i>]]></bottom> </javadoc> </target></project>