千辛万苦终于搞好个J2ME的ant用的build.xml(总体是和王森学得)

俺用的是JDK1.5,WTK2.5.2,apache-ant-1.7.0,retroguard-v2.3.1
俺的目录结构是这样的

--下面是build.xml的内容
<?xml version="1.0" encoding="GB2312"?>
<project name="第一个MIDP程序" default="all" basedir=".">
  <!-- 引入位于build.properties之中的常用属性-->
  <property file="build.properties"/>
 
  <target name="prepare" description="准备工作">
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${build.dir.classes}"/>
    <mkdir dir="${build.dir.obfused}"/>
    <mkdir dir="${build.dir.preverified}"/>
    <mkdir dir="${build.dir.bin}"/>
  </target>
 
  <target name="cleandir" description="清除目录">
    <delete dir="${build.dir}"/>
  </target>
 
  <target name="compile" description="编译源代码" depends="prepare">
    <javac debug="on"  bootclasspath="${midp.api}" classpath="${midp.api};."
      srcdir="${src.dir}" destdir="${build.dir.classes}"/>
  </target>

  <target name="beforeobfuse" description="混淆前先打包成JAR" depends="compile">
    <jar basedir="${build.dir.classes}" jarfile="${build.dir.bin.jarunobfus}"/>
  </target>

  <target name="obfuscate" description="使用混淆器" depends="beforeobfuse">
    <java fork="yes" classname="RetroGuard" classpath="${obfuscator.lib};${midp.api};.">
      <arg line="${build.dir.bin.jarunobfus}"/>
      <arg line="${build.dir.bin.jarobfused}"/>
      <arg line="${obfuscator.script}"/>
    </java>
  </target>

  <target name="afterobfuse" description="混淆后再把JAR解包" depends="obfuscate">
    <unzip src="${build.dir.bin.jarobfused}" dest="${build.dir.obfused}"/>
    <delete dir="${build.dir.obfused}/META-INF"/>
  </target>

  <target name="preverify" description="预先审核" depends="afterobfuse">
    <exec executable="${midp.home}/bin/preverify1.1">
      <arg line="-classpath ${midp.api};."/>
      <arg line="-d ${build.dir.preverified}"/>
      <arg line="${build.dir.obfused}"/>
    </exec>
  </target>

  <target name="package" description="包装成JAR与JAD" depends="preverify">
    <jar basedir="${build.dir.preverified}" jarfile="${build.dir.bin.jar}" manifest="MANIFEST.MF">
      <fileset dir="${res.dir}"/>
    </jar>
    <copy file="${jad}" tofile="${build.dir.bin}/${jad}"/>
  </target>
 
  <target name="run" description="使用模拟器执行">
    <exec executable="${midp.home}/bin/emulator">
      <arg line="-Xdescriptor:${build.dir.bin}/${jad}"/>
    </exec>
  </target>

  <target name="all" description="完成所有步骤" depends="cleandir,package,run"/>
   
</project>

--下面是build.properties的内容
#此文件用来设定一些常用属性

#项目名称
name=MyFirst

#JAD与JAR的文件名
jar=${name}.jar
jad=${name}.jad

#源文件所在路径
src.dir=src

#资源文件所在路径
res.dir=res

#建构产物放置位置
build.dir=build

#编译后类文件的放置位置
build.dir.classes=${build.dir}/classes
#未经过混淆的JAR文件名
build.dir.bin.jarunobfus=${build.dir.bin}/${name}-unobfus.jar
#经过混淆的JAR文件名
build.dir.bin.jarobfused=${build.dir.bin}/${name}-obfused.jar
#混淆后类的放置位置
build.dir.obfused=${build.dir}/obfused

#经过预先审核之后的类文件放置位置
build.dir.preverified=${build.dir}/preverified

#JAD与JAR的放置位置
build.dir.bin=${build.dir}/bin
#最终的JAR文件名
build.dir.bin.jar=${build.dir.bin}/${jar}

#J2ME Wireless Toolkit所在路径,这个路径前的/耽误我很长时间
midp.home=D:/WTK252

#MIDP程序库所在路径
midp.api=${midp.home}/lib/midpapi21.jar;${midp.home}/lib/cldcapi11.jar

#空白MIDP程序库所在路径
midp.emptyapi=${midp.home}/wtklib/kenv.zip

#混淆器与控制文件
obfuscator.lib=retroguard.jar
obfuscator.script=script.rgs


--下面是script.rgs文件内容
.class my/DirstMIDlet

--下面是MANIFEST.MF文件内容
MIDlet-Name: HelloWorld
MIDlet-Version: 1.0.0
MIDlet-Vendor: Sun Microsystems,Inc.
MIDlet-Description: Sample Hello World MIDlet
MIDlet-Info-URL: http://java.sun.com/j2me/
MIDlet-1: HelloWorld,, my.FirstMIDlet
MicroEdition-Profile: MIDP-2.1
MicroEdition-Configuration: CLDC-1.1

--下面是MyFirst.jad文件内容
MIDlet-Name: HelloWorld
MIDlet-Version: 1.0.0
MIDlet-Vendor: Sun Microsystems,Inc.
MIDlet-Description: Sample Hello World MIDlet
MIDlet-Info-URL: http://java.sun.com/j2me/
MIDlet-Jar-URL: MyFirst.jar
MIDlet-Jar-Size: 1020
MIDlet-1: HelloWorld,, my.FirstMIDlet
MicroEdition-Profile: MIDP-2.1
MicroEdition-Configuration: CLDC-1.1

你可能感兴趣的:(千辛万苦终于搞好个J2ME的ant用的build.xml(总体是和王森学得))