build.xml
-------------------------------------------------------------------------------
<?xml version="1.0" ?>
<project name ="antPro" default ="jar" basedir =".">
<property file="${basedir}/build.properties" />
<property name ="Author" value ="NHYE | 80010556"/>
<target name="init">
<mkdir dir="${build.dir}" />
<mkdir dir="${classes.dir}" />
<mkdir dir="${jar.dir}" />
</target>
<target name="clean">
<delete dir="${jar.dir}"/>
</target>
<target name="getAntVersion" if ="ant.version">
<echo message ="Ant 版本: ${ant.version}"/>
</target>
<target name="getJavaVersion" if ="ant.java.version">
<echo message ="Java 版本: ${ant.java.version}"/>
</target>
<target name="noJava" unless ="ant.java.version">
<echo message ="不好意思,,請先裝好Java,再來運(yùn)行,!"/>
</target>
<target name="getBaseDir">
<echo message="根目錄: ${basedir}"/>
</target>
<target name="compile" depends ="clean,init" >
<javac srcdir ="${src.dir}" destdir ="${classes.dir}" includeantruntime="on"/>
</target>
<target name="run" depends ="compile">
<java classname ="${mainclass}">
<classpath>
<pathelement path="${classes.dir}"/>
</classpath>
</java>
</target>
<target name="jar" depends="compile">
<jar destfile="${jar.dir}/${jar.filename}" basedir="${classes.dir}">
<fileset dir="${lib.dir}"/>
<manifest>
<attribute name="Author" value="${Author}" />
<attribute name="Main-class" value="${mainclass}"/>
</manifest>
</jar>
<delete dir="${build.dir}"/>
</target >
<target name="encryptjar" depends="compile">
<jar destfile="${jar.dir}/${jar.tempname}" basedir="${classes.dir}">
<fileset dir="${lib.dir}"/>
<manifest>
<attribute name="Author" value="${Author}" />
<attribute name="Main-class" value="${mainclass}"/>
</manifest>
</jar>
<taskdef resource="${proguard.propertie}" classpath="${proguard.classpath}" />
<proguard configuration="conf/proguard.pro">
-injars '${jar.dir}/${jar.tempname}'
-outjars '${jar.dir}/${jar.filename}'
-libraryjars '.\proguard\rt.jar'
-libraryjars '${lib.dir}'
</proguard>
<delete dir="${build.dir}"/>
</target >
</project>
build.properties
-----------------------------------------------------------------------
name=NHYE_Program
version=0.1
year=2012
basedir = ./
src.dir = ${basedir}/src
lib.dir=${basedir}/lib
build.dir = ${basedir}/build
classes.dir = ${build.dir}/classes
jar.dir=${basedir}/jar
jar.filename=nhye.jar
jar.tempname=nhyetemp.jar
proguard.classpath=${basedir}/proguard/proguard.jar
proguard.propertie=./proguard/proguard.properties
proguard.lib=${src.dir}/lib
mainclass=com.nhye.demo.Testdemo