<?XML version="1.0" encoding="GBK"?><project name="
"deploy.dir" value="${basedir}\deploy"/> <property name="package.dir" value="${basedir}\package"/> <property name="package.extract.dir" value="${package.dir}\extract"/> <property name="preverifIEd.dir" value="${basedir}\preverifIEd"/> <property name="preverifIEd.noObfusedClass.dir" value="${preverifIEd.dir}\noObfused\classes"/> <property name="preverifIEd.obfusedClass.dir" value="${preverifIEd.dir}\obfused\classes"/> <property name="preverify.bin" value="${wtk.home.dir}\bin\preverify.exe"/> <property name="emulator.bin" value="${wtk.home.dir}\bin\emulator.exe"/> <property name="proguard.lib.dir" value="${basedir}\lib"/> <property name="jad.file" value="${programName}.jad"/> <target name="init" description="初始化環境"> <echo message="初始化目錄"/> <delete dir="${build.dir}"/> <delete dir="${deploy.dir}"/> <delete dir="${package.dir}"/> <delete dir="${preverifIEd.dir}"/> <mkdir dir="${build.dir}"/> <mkdir dir="${deploy.dir}"/> <mkdir dir="${package.dir}"/> <mkdir dir="${package.extract.dir}"/> <mkdir dir="${preverifIEd.dir}"/> <mkdir dir="${preverifIEd.noObfusedClass.dir}"/> <mkdir dir="${preverifIEd.obfusedClass.dir}"
/> </target> <target name="complIE" depends="init" description="編譯"> <echo message="編譯程序"/> <Javac srcdir="${src.dir}" destdir="${build.dir}"> <bootclasspath path="${midp.lib.dir}"/> <classpath> <fileset dir="${midp.lib.dir}" includes="*.jar"/> </classpath> </Javac> </target> <target name="verifyForNoObfuscate" description="驗證J2ME的class,將驗證後的class輸出到${preverifIEd.noObfusedClass.dir}"> <echo message="驗證天生的class,將驗證後的class輸出到${preverifIEd.noObfusedClass.dir}"/> <exec executable="${preverify.bin}" searchpath="false"> <arg line="-classpath ${midp.lib.path}"/> <arg line="-d ${preverifIEd.noObfusedClass.dir}"/> <arg line="${build.dir}"/> </exec> </target> <target name="genManifest" description="根據模板屬性文件的值天生Manifest文件"> <echo message="根據模板屬性文件的值天生Manifest文件"/> <!-- 應用${programName}調換掉屬性文件GEN.propertIEs中的@PROGRAMNAME@ --> <replace file="GEN.propertIEs" token="@PROGRAMNAME@" value="${programName}" /> <!-- 應用GEN.propertIEs文件中的屬性值調換掉模板文件MANIFEST.tmp中的對應屬性值, 將調換後的數據復制到${src.dir}\MANIFEST.MF --> <copy file="MANIFEST.tmp" tofile= "${src.dir}\MANIFEST.MF"> <filterset begintoken="@" endtoken="@"> <filtersfile file="GEN.propertIEs"/> </filterset> </copy> </target> <target name="package" description="將class打包,輸出到${package.dir}"> <echo message="將class打包,輸出到${package.dir}"/> <jar basedir="${preverifIEd.noObfusedClass.dir}" jarfile="${package.dir}\${programName}-noObfused.jar" manifest="${src.dir}\MANIFEST.MF" > <fileset dir="${res.dir}" includes="**/*.png"/> </jar> </target> <target name="obfuscate" description="對打包後的jar文件進行混雜,然後解壓縮至${package.extract.dir}"> <echo message="對打包後的jar文件進行混雜,然後解壓縮至${package.extract.dir}"/> <Java fork="true" classname="proguard.ProGuard"> <classpath path="${proguard.lib.dir}\proguard.jar"/> <arg line="-libraryjars ${midp.lib.path}"/> <arg line="-injar ${package.dir}\${programName}-noObfused.jar"/> <arg line="-outjar ${package.dir}\${programName}-obfused.jar"/> <!--保留MIDlet的類聲明不被混雜--> <arg line="-keep 'public class * extends Javax.microedition.midlet.MIDlet'"/> <!--打印被保留的類名--> <arg line="-printseeds"/> </Java> <unjar src="${package.dir}\${programName}-obfused.jar" dest="${package.extract.dir}" /> </target> <target name="verifyForObfuscate" description="驗證被混雜的class,輸出到${preverifIEd.obfusedClass.dir}"> <echo message="驗證被混雜的class,輸出到${preverifIEd.obfusedClass.dir}"/> <exec executable="${preverify.bin}" searchpath="false"> <arg line="-classpath ${midp.lib.path}"/> <arg line="-d ${preverifIEd.obfusedClass.dir}"/> <arg line="${package.extract.dir}"/> </exec> <copy todir="${preverifIEd.obfusedClass.dir}"> <fileset dir="${package.extract.dir}" includes="**/*.png"/> </copy> </target> <target name="deploy" description="將經過驗證的混雜後的class打包,安排在delpoy目錄"> <echo message="將經過驗證的混雜後的class打包,安排在${deploy.dir}目錄"/> <jar basedir="${preverifIEd.obfusedClass.dir}" jarfile="${deploy.dir}\${programName}.jar" manifest="${src.dir}\MANIFEST.MF" > <fileset dir="${preverifIEd.obfusedClass.dir}" includes="**/*.class;*.png"/> </jar> </target> <target name="genJad" description="在${deploy.dir}目錄天生JAD文件"> <echo message="在${deploy.dir}目錄天生JAD文件"/> <length file="${deploy.dir}\${programName}.jar" property="jarsize"/> <echo message="獲得jar文件長度:${jarsize}"/> <replace file="GEN.propertIEs" token="@JARSIZE@" value="${jarsize}" /> <replace file="GEN.propertIEs" token="@PROGRAMNAME@" value="${programName}"
/> <copy file="JAD.tmp" tofile="${deploy.dir}\${programName}.jad"> <filterset begintoken="@" endtoken="@"> <filtersfile file="GEN.propertIEs"/> </filterset> </copy> </target> <target name="recoveryGenPropertIEs" description="恢復被修正的GEN.propertIEs"> <echo message="恢復被修正的GEN.propertIEs"/> <replace file="GEN.propertIEs" token="MIDLET_NAME=${programName}" value="MIDLET_NAME=@PROGRAMNAME@" /> <replace file="GEN.propertIEs" token="MIDLET_JAR_URL=${programName}.jar" value="MIDLET_JAR_URL=@[email protected]" /> <replace file="GEN.propertIEs" token="MIDLET_JAR_SIZE=${jarsize}" value="MIDLET_JAR_SIZE=@JARSIZE@" /> </target> <target name="run" description="在模仿器中運行"> <echo message="在模仿器中運行..."/> <exec executable="${emulator.bin}" searchpath="false"> <arg line="-classpath ${deploy.dir}\${programName}.jar;${wtk.lib.path}"/> <arg line="-Xdescriptor:${deploy.dir}\${jad.file}"/> </exec> </target> <target name="end" depends="complie,verifyForNoObfuscate,genManifest,package,obfuscate,verifyForObfuscate,deploy,genJad,recoveryGenPropertIEs,run"/></project>.dir}\\libmidp.lib.path=${midp.lib.dir}\\cldcapi11.jar;${midp.lib.dir}\\midpapi20.jar
天生屬性文件:GEN.propertIEs
MIDLET_NAME=@PROGRAMNAME@MIDLET_VERSION=1.0.0MIDLET_VENDOR=kevinMIDLET_01_NAME=MainMidletMIDLET_01_LOGO=MIDLET_01_CLASS=com.gamecollege.work.menu.MainMidletMIDLET_JAR_URL=@[email protected]_JAR_SIZE=@JARSIZE@ME_PROFILE=MIDP-2.0ME_CONF=CLDC-1.1
Manifest模板文件:MANIFEST.tmp
MIDlet-Name: @MIDLET_NAME@MIDlet-Version: @MIDLET_VERSION@MIDlet-Vendor: @MIDLET_VENDOR@MIDlet-1: @MIDLET_01_NAME@,@MIDLET_01_LOGO@,@MIDLET_01_CLASS@MicroEdition-Profile: @ME_PROFILE@MicroEdition-Configuration: @ME_CONF@
JAD模板文件:JAD.tmp
MIDlet-Name: @MIDLET_NAME@MIDlet-Version: @MIDLET_VERSION@MIDlet-Vendor: @MIDLET_VENDOR@MIDlet-Jar-URL: @MIDLET_JAR_URL@MIDlet-Jar-Size: @MIDLET_JAR_SIZE@MIDlet-1: @MIDLET_01_NAME@,@MIDLET_01_LOGO@,@MIDLET_01_CLASS@MicroEdition-Profile: @ME_PROFILE@MicroEdition-Configuration: @ME_CONF@