1. ant中变量的传递有两种方法:
a) set env,然后在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}" failonerror="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>