关于ANT,比较早前就听过了,可是一直没学,今天看了下。
关于ANT,主要是对build.xml的书写。target表示任务,应该就是ANT执行的任务,包括初始化,产生javadoc,jar等功能。property 表示属性,location表示目录。
下面是对此书第一章大部分的表述。
<?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="reports.dir" location="reports"/> <property name="lib" location="lib"/> <!--保存项目需要的jar--> <property name="reports.javadoc" location="reports/javadoc"/> <property name="reports.data.dir" location="${reports.dir}/xml"/> <property name="reports.html.dir" location="reports/html"/> <property name="project.name" value="${ant.project.name}"/> <property name="project.version" value="1.0"/> <property name="tomcat.install.dir" location="E:/jdk/apache-tomcat-6.0.16"/> <property name="web.dir" location="web"/> <property name="dist.dir" location="dist"/> <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="${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="${tests.dir}" destdir="${test.classes.dir}"> <classpath refid="test.compile.classpath"/> </javac> </target> <target name="test" depends="compile-tests" description="Run unit tests"> <junit printsummary="true" haltonfailure="false" failureproperty="test.failures" fork="true"> <assertions> <enable package="ynu.edu"/> </assertions> <classpath refid="test.classpath"/> <formatter type="xml"/> <formatter type="plain"/> <batchtest todir="${reports.data.dir}"> <!--reports保存的目录--> <fileset dir="${test.classes.dir}" includes="**/*Test.class"/> </batchtest> <!--<test name="com.ynu.edu.TaxRateTest" />--> </junit> </target> <target name="test.report" depends="test" description="Generate HTML unit test reports"> <junitreport todir="${reports.data.dir}"> <fileset dir="${reports.data.dir}"> <include name="TEST-*.xml"/> </fileset> <report format="frames" todir="${reports.html.dir}"/> </junitreport> </target> <target name="test.report" depends="test" description="Generate HTML unit test reports"> <junitreport todir="${reports.data.dir}"> <fileset dir="${reports.data.dir}"> <include name="TEST-*.xml"/> </fileset> <report format="noframes" todir="${reports.html.dir}"/> </junitreport> <fail if="test.failures" message="There were test failures."/> </target>
<target name="javadoc" depends="compile,init" description="Generate JavaDocs."> <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 All Rights Reserved. </i>]]></bottom> </javadoc> </target> <target name="package" depends="compile" description="Generate JAR file"> <jar destfile="${dist.dir}/${project.name}-${project.version}.jar" basedir= "${build.classes.dir}"/>
从多个源文件获得 <jar destfile="${dist.dir}/${project.name}-${project.version}.jar"> <fileset dir="${build.classes.dir}"/> <fileset dir="src/resources"/> </jar> </target> <!--向MANIFEST.MF添加一些关于项目的信息,如时间,作者,版本--> <target name="package" depends="compile" description="Generate JAR file"> <tstamp> <format property="build.date" pattern="EEEE, d MMMM yyyy"/> <format property="build.time" pattern="hh:mm a"/> </tstamp> <jar destfile="${dist.dir}/${project.name}-${project.version}.jar" basedir="${build.classes.dir}"> <manifest> <attribute name="Built-By" value="${user.name}"/> <attribute name="Specification-Title" value="${project.name}"/> <attribute name="Specification-Version" value="${project.version}"/> <attribute name="Specification-Vendor" value="ACME Incorporated"/> <attribute name="Implementation-Title" value="common"/> <attribute name="Implementation-Version" value="${project.version} - built at ${build.time} on ${build.date} "/> <attribute name="Implementation-Vendor" value="ACME Incorporated"/> </manifest> </jar> </target> <!--产生WEB的war文件,对于修改MANIFEST.MF与产生jar相似--> <target name="war" depends="compile" description="Generate WAR file"> <war destfile="${dist.dir}/${project.name}-${project.version}.war" webxml="${web.dir}/WEB-INF/web.xml"> <fileset dir="${web.dir}"/> <classes dir="${build.classes.dir}"/> <lib dir="${lib}"> <include name="*.jar"/> </lib> </war> </target> <!--对于ear(EJB)的处理 --> <target name="ear" depends="war" description="Generate EAR file"> <ear destfile="${dist.dir}/${project.name}-${project.version}.ear" appxml="src/metadata/application.xml"> <fileset file="${dist.dir}/${project.name}-${project.version}.war"/> <fileset dir="${ear.lib}"> <include name="*.jar"/> </fileset> </ear> </target> <!--web应用war文件的部署--> <target name="local.deploy" depends="war" description="Deploy to local Tomcat instance"> <copy file="${dist.dir}/${project.name}-${project.version}.war" todir="${tomcat.install.dir}/webapps"/> </target> <!--对于war文件的重命名--> <target name="local.deploy" depends="war" description="Deploy to local Tomcat instance"> <copy file="${dist.dir}/${project.name}-${project.version}.war" tofile="${tomcat.install.dir}/webapps/${project.name}.war" /> </target> <!--复制一个目录下的所有文件--> <target name="local.documentation" depends="javadoc" description="Deploy documentation to local web server"> <copy todir="${web.dir}/${project.name}/javadoc"> <fileset dir="${reports.javadoc}"/> </copy> </target> </project>
|
以上就是对于ANT的一些基本应用,但不包括此书后面的XMLTask的使用。
阅读(973) | 评论(0) | 转发(0) |