刚刚学习了ANT 做了一个实例,记录下来分享AND备忘.
<?xml version="1.0"?>
<!--默认首先执行clean-->
<project default="clean" basedir=".">
<!--设置目录变量-->
<property name="destpath" location="dest"/>
<property name="srcdir" location="src"/>
<property name="libdir" location="lib"/>
<!--设置第三方类库-->
<path id="Third-Part Lib">
<fileset dir="${libdir}">
<include name="**/*.jar" />
</fileset>
</path>
<!--新建目录-->
<target name="init">
<mkdir dir="${destpath}"/>
</target>
<!--编译原文件 classpath 设置上面定义好的类库-->
<target name="compile" depends="init">
<javac srcdir="${srcdir}" destdir="${destpath}">
<classpath refid="Third-Part Lib"/>
</javac>
</target>
<!--复制${srcdir}目录下所有properties文件到${destpath}中去-->
<target name="copyproperty" depends="compile">
<copy todir="${destpath}">
<fileset dir="${srcdir}">
<include name="**/*.properties"/>
</fileset>
</copy>
</target>
<!--解压 ${libdir} 下所有 jar 文件到${destpath}中去-->
<target name="unjarfile" depends="copyproperty">
<unzip dest="${destpath}">
<fileset dir="${libdir}">
<include name="**/*.jar" />
</fileset>
</unzip>
</target>
<!--打包 ${destpath}目录下所有文件 并设置相关JAR包属性-->
<target name="dist" depends="unjarfile">
<jar destfile="createindex.jar" basedir="${destpath}">
<manifest>
<attribute name="Main-Class" value="com.createinex.CreateIndex"/>
</manifest>
</jar>
</target>
<!--删除${destpath}目录-->
<target name="clean" depends="dist">
<delete dir="${destpath}"/>
</target>
</project>