1.读取系统环境变量 以及echo命令
<property environment="env"/>
<property name="env.home" location="${env.HOME}"/>
<echo message="env.home=${env.home}" />
2. <tstamp/>:
Sets the DSTAMP, TSTAMP, and TODAY properties in the current project, based on the current date and time.
<target name="init">
<tstamp/>
<echo message="DSTAMP=${DSTAMP}" />
<echo message="${DSTAMP}" />
<echo message="${TSTAMP}" />
</target>
结果:
init:
[echo] DSTAMP=20210803
[echo] 20210803
[echo] 1136
3.target依次调用
<?xml version="1.0" encoding="UTF-8"?>
<project default="setup" basedir=".">
<property name="dir.lib" location="${basedir}/lib"/>
<property name="dir.lib.main" location="${dir.lib}/main"/>
<property name="dir.antlib" location="${user.home}/.ant/lib"/>
<property name="overwrite.deps" value="true"/>
<property name="ant-contrib.jar" location="${dir.lib.main}/ant-contrib-1.0b3.jar"/>
<property name="maven-artifact-ant.jar" location="${dir.lib.main}/maven-artifact-ant-2.0.4.jar"/>
<target name="init">
<tstamp/>
</target>
<target
name="setup"
depends="init"
description="Set up build environment."
>
<antcall target="setup.deps"/>
</target>
<target
name="setup.deps"
depends="init"
description="Set up dependencies."
>
<mkdir dir="${dir.antlib}"/>
<copy
tofile="${dir.antlib}/ant-contrib.jar"
file="${ant-contrib.jar}"
overwrite="${overwrite.deps}"
/>
<copy
tofile="${dir.antlib}/maven-artifact-ant.jar"
file="${maven-artifact-ant.jar}"
overwrite="${overwrite.deps}"
/>
</target>
</project>