ANT介绍及安装及配置

来源:互联网 发布:淘宝卖家首页装修 编辑:程序博客网 时间:2024/04/29 07:09
-. Ant简介
 Ant是一个类似make的工具,用来编译/运行/测试java程序。
 构建、包装和发布过程中几乎每一件事都可以由Ant的任务来处理.
 
二.Ant的安装及配置
 你可以从Jakata网站下载预编译的ANT,解压至任一目录;
 设置自己的环境变量,即ANT_HOME,指向解压目录;
 设置JAVA_HOME环境变量,指向jdk的根目录;
 
三:用ant管理项目
Ant一启动就会自动地加载一个叫做Build.xml的项目配置文件。如果想给这个项目配置文件取别的名字,你可以使用buildfile标记来运行ant,就像下面这样:
ant -buildfile Project_configuration.xml
主要特点:
 使用xml文件作为配置文件,即build.xml;
 可与junit作无缝整合,达到系统测试、编译到发布的功能;
 强大、详细的报表功能;
 控制灵活,可自定义要执行的任务组合。
build.xml主要节点:
proejct 项目
 name  指定工程名称
 default  指定默认的target(即任务)
 basedir  指定系统的基本路径
property 属性,类似于全局变量
 name  变量名称
 value  变量值
 属性访问方法: ${property}
 内置属性:
 basedir             工程的路径.
 ant.file            build文件的路径.
 ant.version         版本
 ant.project.name    工程名
 ant.java.version    jvm版本
 
target 目标,即任务
 name  指定目标名称
 depends  指定所依整的目标
 if  条件,可达到控制流程目的
 unless
 description
task 一小段的任务
reference 引用
 通过refid属性来引用在其他节中定义的id
内置命令:
        <tstamp/>  建立时间
        <mkdir dir="${var}"/> 建立目录
 编译文件:
        <javac srcdir="${src}" destdir="${classes}" debug="off">
            <classpath refid="appclasspath"/>
            <include name="**/*.java" />
        </javac>
 执行文件:
        <exec executable="${base.dir}/email.bat" >
        </exec>
 junit命令:
      <junit>
        <classpath refid="appclasspath"/>
        <classpath>
          <pathelement location="${base.dir}/defaultroot/WEB-INF/classes"/>
        </classpath>
        <formatter type="xml"/>
        <test name="junit.tests.AllTests" haltonfailure="no" outfile="result"/>
      </junit>
      <junitreport todir="./report">
        <fileset dir=".">
          <include name="result.xml"/>
        </fileset>
        <report format="noframes" todir="./report"/>
      </junitreport>

四:运行ant
ant [options] [target [target2 [target3] ...]]
Options:
  -logfile <file>        use given file for log
    -l     <file>                ''
  -buildfile <file>      use given buildfile
    -file    <file>              ''
    -f       <file>              ''
  -D<property>=<value>   use value for given property
  -propertyfile <name>   load all properties from file with -D
                         properties taking precedence


 
原创粉丝点击