ant--转自王俊blog

一直想写一个持续集成的ant build.xml,可惜试了一阵子也没有成功,也懒得去查文档了.今天偶然看到一个网友写的build.xml,从中借用并修改后就搞定了.记录一下几个有用的task,免得忘记.

1.cvs

进行cvs操作的有关task: cvs,cvspass等.

<target name="cvs">
<delete dir="${app.name}" />
<cvspass cvsroot="${cvsroot}" password="anonymous"/>
<cvs cvsRoot="${cvsroot}"
package="${app.name}"
dest="${basedir}"
/>
</target>

2.antcall

调用同一个build.xml中的其它target.

<target name="build" >
<antcall target="callscript-build" />
</target>

3.ant

调用其它build.xml,一般就是用来构建子工程.这里面inheritAll属性应该要注意一下,缺省值是true,也就是使用当前build.xml(父)的所有属性.如果在被你调用的build.xml也设有属性,最好把它设置为false.

<ant antfile="build.xml" dir="${project.home.dir}" target="main" inheritAll="false" output="callscript.log" />

4.exec

调用本地命令,不同的操作系统语法不太一样.
<exec executable="cmd.exe" os="Windows 2000">
<arg line="/c dir"/>
</exec>


5.property

定义build.xml中的属性.这个task大家太熟悉了.我这里要提的是使用它引入属性定义文件.因为这样可以保证build.xml不是正常改变,而各人只修改自己的属性文件.

<property file="build.properties"/>

build.properties

---------------------------------------

app.name=CS

tomcat.home=C:/Tomcat //开发人员的tomcat路径很可能是不一样的

6.junit

junit就是为了集成单元测试.这是maven自动生成的build.xml中关于单元测试的target.

<target name="internal-test" depends="compile-tests">
<mkdir dir="${testreportdir}">
</mkdir>
<junit dir="./" failureproperty="test.failure" printSummary="yes" haltοnerrοr="true" fork="true">
<sysproperty key="basedir" value=".">
</sysproperty>
<formatter type="xml">
</formatter>
<formatter usefile="false" type="plain">
</formatter>
<classpath>
<fileset dir="${libdir}">
<include name="*.jar">
</include>
</fileset>
<pathelement path="${testclassesdir}">
</pathelement>
<pathelement path="${classesdir}">
</pathelement>
</classpath>
<batchtest todir="${testreportdir}">
<fileset dir="E:\workspace\projects\maven\src\test">
<include name="**/HTMLMarkupTest.java">
</include>
<exclude name="**/NaughtyTest.java">
</exclude>
</fileset>
</batchtest>
</junit>
</target>



7.path和classpath

path和classpath不能算是task,而更应该象target,或者说是一个tag.其实就是定义你需要引用的类库.这里面还有一个专业名词:path-like structure.下面是一些基本用法:

<path id="base.path">
<pathelement location="${tomcat.home}/common/lib/servlet.jar"/>
</path>


<path id="project.path">
<path refid="base.path"/>
<pathelement location="${lib}/log4j-1.2.8.jar"/>
<pathelement location="${build}"/>
</path>

<classpath>
<pathelement path="${classpath}"/>
</classpath>


<classpath>
<pathelement path="${classpath}"/>
<fileset dir="lib">
<include name="**/*.jar"/>
</fileset>
<pathelement location="classes"/>
<dirset dir="${build.dir}">
<include name="apps/**/classes"/>
<exclude name="apps/**/*Test*"/>
</dirset>
<filelist refid="third-party_jars"/>
</classpath>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值