ant的build.xml文件分析

build.xml

1. ant中变量的传递有两种方法:

a) setenv,然后在build.xml中获取系统环境变量,e.g. setenv ANT_HOME xxxx

b) ant -D变量名=变量值 target_name,则在build.xml中可以直接使用该变量, e.g. ant -Dlsf.version=6.2 all (build.xml见下)

########################################<?xml version="1.0" encoding="UTF-8"?>

<!-- 定义default target,以及当前目录 -->

<project name="xxx" default="all" basedir=".">

<!-- 定义一些变量,直接指定其值 -->

<property name="perf.version" value="1.2"></property>

<!-- 定义一些变量,其值从环境变量获取 -->

<property environment="env"></property>

<property name="bname" value="${env.ANT_HOME}"></property>

<!-- 定义一些变量,其值是基于其他的变量值 -->

<property name="perf.home" value="${basedir}/../.."></property>

<property name="bname" value="${env.BNAME}"></property>

<property name="ant.home" value="${env.ANT_HOME}"></property>

<!-- 通过 Condition 定义一些变量,其值根据不同的条件设定不同的值 -->

<condition property="cmd.ant" value="${ant.home}\bin\ant.bat">

<!-- ant 定义并自动获取的os type -->

<os family="windows"></os>

</condition>

<condition property="cmd.ant" value="${ant.home}/bin/ant">

<not>

<os family="windows"></os>

</not>

</condition>

<condition property="node.lsflib.dir" value="linux-x86">

<equals arg1="${bname}" arg2="linux-x86"></equals>

</condition>

<condition property="node.lsflib.dir" value="linux-x86_64">

<equals arg1="${bname}" arg2="linux-x86_64"></equals>

</condition>

......

<condition property="build" value="true">

<or>

<equals arg1="${bname}" arg2="linux-x86"></equals>

<equals arg1="${bname}" arg2="linux-x86_64"></equals> ...... </or>

</condition>

<!-- 这里lsf.version 就是通过 ant -Dlsf.version=xxx 传进来的-->

<condition property="lsf.shared.dir" value="LSF6.2">

<contains string="${lsf.version}" substring="6.2">

</contains>

</condition>

<condition property="lsf.shared.dir" value="LSF7_0_4_Gold_Patch">

<contains string="${lsf.version}" substring="7.0"></contains>

</condition>

......

<!-- Get build date -->

<tstamp>

<format property="build.date" pattern="EEE MMM dd HH:mm:ss yyyy">

</format>

</tstamp>

<path id="compile.classpath">

<pathelement location="${classes.dir}"></pathelement>

<fileset dir="${perf.home}/xxx/lib">

<include name="*.jar"></include>

</fileset>

</path>

<!--可以用 if 或者 unless 设定在什么条件下执行该target-->

<target name="all" if="build">

<antcall target="xxx"></antcall>

<antcall target="xxx"></antcall>

......

</target>

<target name="xxx">

<!--到某个目录下执行ant命令或其他-->

<exec dir="${perf.home}/xxx" executable="${cmd.ant}" failοnerrοr="true">

<arg line="clean"></arg>

<arg line="build"></arg>

</exec>

</target>

</project>


<unzipsrc="a.zip" dest="test">

<patternset>

<includename="a/b/**/*"/>

</patternset>

<globmapperfrom="a/*" to="*" casesensitive="no"/>

</unzip>


<target name="run">

<echo message="${serverpath}"/>
<unzip src="Calculator.zip" dest="test">
<patternset>
<include name="**/*"/>
<!--<include name="**/**/*"/>-->
</patternset>
<globmapper from="*" to="new/*" casesensitive="no"/>
</unzip>
</target>



http://ant.apache.org/manual/Tasks/unzip.html



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值