<!-- print classpath -->
<path id="somePathId">
<pathelement path="someDir"/>
</path>
<property name="debug.classpath" refid="somePathId"/>
<echo message="Classpath = ${debug.classpath}"/>
<!-- modify path -->
<path id="p1">
<fileset dir="lib">
<include name="**/*.jar"/>
</fileset>
</path>
<path id="p2">
<path refid="p1"/>
<fileset dir="src">
<include name="**/*.java"/>
</fileset>
</path>
<!-- exec -->
<target name="setenv">
<!-- need to specify the absolute path here, or will meet "Cannot run program" exception -->
<exec executable="${current.dir}\setenv.cmd">
<arg value="${pattern.type}"/>
</exec>
</target>
<!--propertyregex -->
<!--1. substring from input, result is "Test_Sample.ear" -->
<propertyregex override="yes" property="server.name" input="WLS_Test_Sample.ear" regexp="(.*?)_(.*)" select="\2"/>
<!-- 2. find and replace, result is "root:pwd@127.0.0.1"-->
<propertyregex property="${svr1}" input="root:password@127.0.0.1" regexp='password' replace="pwd"/>
<!-- macrodef -->
<macrodef name="patternType">
<attribute name="name"/>
<attribute name="version"/>
<sequential>
<var name="@{name}" value="weblogic"/>
<if>
<matches pattern="^[0-5]\.(.*)" string="@{version}"/>
<then>
<var name="@{name}" value="oc4j"/>
</then>
</if>
</sequential>
</macrodef>
<!-- invoking, ${result} is "oc4j" -->
<patternType name="result" version="5.1"/>
<!-- 获取当前ant文件的路径:这将十分有用若当前文件被其它ant文件import,但是当前文件又需要加载其它的文件,此处若用相对路径,往往会找不到要加载的文件-->
<project name="IMPORTED">
<dirname property="IMPORTED.basedir" file="${ant.file.IMPORTED}" />
<property name="myresource" location="${IMPORTED.basedir}/some_resource_file"/>
</project>