关闭

软件质量之路:日构建

发表于:2009-1-20 13:48

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:林星    来源:IBM

  日构建的基本工具

  日构建的工具有很多,但是最基础、最广泛的工具是Ant(http://ant.apache.org)。Ant类似于Make,但是加入了跨平台的特性。在这个目标的驱动下,Ant摒弃了Make工具的给予Shell的缺点,提供了一种使用XML配置文件的构建方式,并定义了一个统一的微核心和强大的扩展机制。这些特点使得Ant很快被人所接受、推广。目前,Ant的最新版本是1.6.0。

<project name="MyProject" default="dist" basedir=".">
    <description>
        simple example build file
    </description>
  <!-- set global properties for this build -->
  <property name="src" location="src"/>
  <property name="build" location="build"/>
  <property name="dist"  location="dist"/>
  <target name="init">
    <!-- Create the time stamp -->
    <tstamp/>
    <!-- Create the build directory structure used by compile -->
    <mkdir dir="${build}"/>
  </target>
  <target name="compile" depends="init"
        description="compile the source " >
    <!-- Compile the java code from ${src} into ${build} -->
    <javac srcdir="${src}" destdir="${build}"/>
  </target>
  <target name="dist" depends="compile"
        description="generate the distribution" >
    <!-- Create the distribution directory -->
    <mkdir dir="${dist}/lib"/>
    <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
    <jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/>
  </target>
  <target name="clean" description="clean up" >
    <!-- Delete the ${build} and ${dist} directory trees -->
    <delete dir="${build}"/>
    <delete dir="${dist}"/>
  </target>
</project>

  以上是一个简单,但已经可以完全说明Ant工作流程的例子,来源于Ant的手册。在这个例子中,先定义了项目的基本信息和构建过程中所需要使用到的属性(1),然后初始化环境(2)(创建时戳和目标目录),在3和4中,对项目进行编译和打包,在5处,提供了清除项目输出的途径。

  在Ant中,最关键的四个概念就是项目(Project)、目标(Target)、任务(Task)和属性(Property)。这四个概念的定义和调度、配置文件的处理构成了Ant的核心。而具体的任务则作为扩展机制。这种微核心的处理思路在很多成功的软件项目中采用过。

  本文并没有打算对Ant进行全面的介绍,因此,如果你打算在组织中引入日构建,那么,学会使用Ant是必须的。目前很多的IDE环境都提供了对Ant的支持(例如Eclipse),所以使用Ant是很方便的。

43/4<1234>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号