hcc2005

统计

留言簿

阅读排行榜

评论排行榜

Java单元测试工具初步(一):ant

n       What is Ant?

Ø       Apache Ant is a Java-based build tool for java.

n       Installing Ant

Ø       Set path environment first:(JAVA_HOME)

Ø       Download Binary Edition: http://ant.apache.org/builds/ant/

n       Using Ant

Ø       Configuration file:build.xml

Ø       The build.xml contains main elements:

•        project

•        targets

•        tasks and properties

Ø        build.xml simple:

•        <project name="Money" default="all" basedir=".">

•              <property name="src"     value="src"/>

•              <property name="build"  value="bin"/>

•              <property name="lib"      value="lib"/>

•              <path id="1">

•                     <pathelement location="${lib}/junit.jar"/>

•             </path>  

•              <target name="init">

•                        <mkdir dir="${build}"/>

•              </target>

•              <target name="compile" depends="init">

•                     <javac srcdir="${src}" destdir="${build}">

•                            <classpath refid="1"/>

•                     </javac>

•            </target>      

•              <target name="all" depends="compile" />

•        </project>

Ø       Project

•        A project defines the name of project that you will build.

•        It have three attributes:

n       name,default,basedir

Ø       Targets

•        A target is a collection of tasks

•        A target can depend on other targets

•        A target includes mainly attributes:

n       name

n       depends

Ø       Tasks

•        A target can have a set of tasks(相当于函数)

•        Format :<name attribute1="value1" attribute2="value2" ... />

•        Ant task:

n       built-in tasks(http://ant.apache.org/manual/CoreTasks/)

n       optional tasks(http://ant.apache.org/manual/OptionalTasks/)

Ø       Properties(相当于函数的参数)

•        A project can have a set of properties, a property has a name and a value, the name is case-sensitive. Properties may be used in the value of task attributes. This is done by placing the property name between "${" and "}" in the attribute value.

Ø       Path-like Structures

•        ClassPath can includes :

n       pathelement:path,location

n       Filesets(FileSets are groups of files)

n       <classpath>

n        <pathelement path=< " .;${lib}/junit.jar"/>

n       Or  <pathelement location=< " ." />

n             <pathelement location=< " ${lib}/junit.jar" />

n       Or <pathelement location=< " ." />

n            <fileset dir= " ${lib}" >

n                 <inlcude name= "**/*.jar " >

n            </fileset >

n       </classpath>

•        Path id structure(see before buildfile)

Ø       Condition Targets

•        Target’s properties: if,unless

•        Example:

•              <target name="init"  if="make">

•                        <mkdir dir="${build}"/>

•              </target>

•              <target name="init"  unless="make">

•                        <mkdir dir="${build}"/>

•              </target>

•        Execute at Command line: ant –buildfile build.xml –Dmake=true

Ø       Hierarchy build

•        A project build.xml include subproject’s buildfile.

•        <ant antfile=“/buildif.xml”>

•        <property name=“make” value=“true”>

•        </ant>

n       Execute ant:

Ø       Command line enter:ant

Ø       Or:ant –buildfile [path]build.xml

Ø       Or:ant  [-find]

 

posted on 2005-02-03 09:42 龙溪过客 阅读(273) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: