Ant常用Task

1.      设置classpath

<target>

       <javac>

              <classpath refid=”project.class.path”/>

       </javac>

<target>

 

<classpath id=”project.class.path”>

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

       <fileset dir=”lib”>

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

       </fileset>

       <pathelement location=“classes”/>

       <direst dir=”build”>

              <include name=”apps/**/classes”/>

              <exclude name=”apps/**/*Test*”/>

       </direst>

       <filelist refid=”third-party_jars”/>

</classpath>

 

2.      输出信息

<echo message=”xxx”/>

 

<echo>yyyy</echo>

 

3.      拷贝文件

拷贝文件:

<copy file=”myfile.txt”tofile=”mycopy.txt”/>

 

拷贝文件到目录

<copy file=”myfile.txt”todir=”../some/other/dir”/>

 

拷贝目录到另一目录

<copy todir=”../new/dir”>

       <fileset dir=”sir_dir”/>

</copy>

 

拷贝文件集合到目录

<copy todir=”../dest/dir”>

       <fileset dir=”src_dir”>

              <exclude name=”**/*.java”/>

       </fileset>

</copy>

 

 

4.      删除文件,目录

<delete file=”/lib/ant.jar”/>

 

<delete dir=”lib”/>

 

<delete>

       <fileset dir=”.” includes=”**/*.bak”/>

</delete>

 

5.      移动文件,目录

<move todir=”some/new/dir”>

       <fileset dir=”my/src/dir”>

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

              <exclude name=”**/ant.jar”/>

       </fileset>

</move>

 

6.      创建文件,目录

<touch file=”myfile”/>

 

<mkdir dir=”${dist}/lib”/>

7.      设置property

读取环境变量

<propertyenvironment=”env”/>

 

读取属性文件中的属性

<property file=”foo.peoperties”/>

 

设置属性name-value

<property name=”foo.dist”value=”dist”/>

 

读取文件中的属性配置

<propertyresource=”foo.properties”/>

 

 

8.      jar包

<jar destfile=”${dist}/lib/app.jar”

       basedir=”{build}/classes”

       includes=”mypackage/test/**”

       excludes=”**/Test.class”

/>

 

9.      Ear包

<ear destfile=”build/myapp.ear”appxml=”src/metadata/application.xml”>

       <fileset dir”build” includes=”*.jar,*.war”/>

</ear>

 

 

10. 执行程序

<target name=”help”>

       <exec executable=”cmd>

              <arg value=”/c”/>

              <arg value=”ant.bat”/>

              <arg value=”-p”/>

       </exec>

</target>

 

11. 运行jar包

<javaclassname=”test.Main”>

       <arg value=”-h”/>

       <classpath>

              <pathelement location=”dist/test.jar”/>

       </classpath>

</java>

 

12. 编译程序

<javac srcdir=”${src}”

       destdir=”${build}”

       classpath=”xyz.jar”

       debug=”on”

       source=”1.4”

/>

相关推荐