今天改了一个小的 build.xml , 原作者是比较细心, 包括了挺多有用的小 task, 所以blog保留:
平台要求: JDK1.4.2, WTK22, Proguard2.1 或 3.8, Ant 1.6.2, antenna 0.9.13 或 0.9.14 (测试过)
其他平台不清楚, 尤其是 JDK1.5 或 1.6, 可能我比较守旧, 喜欢用旧的东西, 所以非不得意
从来不更新开发平台. 比较部分开发人员总是追求最新的工具, 却不考虑backward compatible的概念.
here we go..................build.xml
<?xml version="1.0" encoding="iso-8859-1" ?>
<!--
================================================================================
peter modify this to make it works on appname, WTK25,
Important to modify: search for CHANGEME
- <taskdef resource="antenna.properties"
classpath="d:\download\kjava\antenna-bin-0.9.14.jar" />
## change the classpath to antenna*.jar (tested on 0.9.13 and 0.9.14)
- wtk.home set to your c:/wtk22 or whatever (tested only on WTK22)
- obfuscate: if you do have proguard, no need to change, else set false
peter: observe that the encoding here is "iso-8859-1", and
the build.xml use in our old projects are in UTF-8.
(does it makes any difference?)
Derived from:
Build file for Funambol J2ME Mail Client.
================================================================================
-->
<project name="appname" default="build">
<!-- Define the tasks. -->
<!-- peter: CHANGEME tested on 0.9.13 and 0.9.14 -->
<!-- pick your version of antenna, and path -->
<!--
<taskdef resource="antenna.properties"
classpath="d:\download\kjava\antenna-bin-0.9.14.jar" />
-->
<taskdef resource="antenna.properties"
classpath="c:\ant\lib\antenna-bin-0.9.13.jar" />
<!--
========================================================================
Setting variable
========================================================================
-->
<target name="init">
<!-- if you run ant on c:\eclipse\workspace\appname,
there is no need to change basedir -->
<property name="basedir" value=""/>
<property name="midlet.version" value="1.0"/>
<property name="jad.filename" value="appname"/>
<property name="jar.filename" value="${jad.filename}"/>
<!-- peter: simplify the dir.src.* to dir.src -->
<property name="dir.src" value="src"/>
<property name="dir.res" value="res" />
<property name="dir.output" value="${basedir}/build" />
<property name="dir.classes" value="${dir.output}/classes" />
<!-- WTK Definitions -->
<!-- peter: CHANGEME c:/wtk22 only teseted on WTK22 -->
<property name="wtk.home" value="c:/wtk22" />
<property name="wtk.cldc.version" value="1.0" />
<property name="wtk.midp.version" value="2.0" />
<!-- peter: changed wma from true to false, no need anyway -->
<property name="wtk.wma.enabled" value="false" />
<property name="wtk.debug" value="false" />
<!-- CHANGEME if you do not have proguard, set value="false" -->
<property name="wtk.obfuscate" value="true" />
<!-- jad thing: midlet-name etc and optionally application def -->
<!-- jad.midlet-* are more essential -->
<property name="jad.midlet-name" value="appname" />
<property name="jad.midlet-vender" value="vendor" />
<property name="jad.midlet-version" value="0.12" />
<property name="jad.midlet-class" value="TestMidlet" />
<property name="jad.midlet-icon" value="" />
<property name="jad.midlet-permissions"
value="javax.microedition.io.Connector.http, javax.microedition.io.Connector.sms, javax.microedition.io.PushRegistry, javax.wireless.messaging.sms.receive"/>
<property name="jad.servername" value="127.0.0.1" />
<property name="jad.serverport" value="5060" />
<!-- Define RMS directory of WTK installation -->
<property name="RMSPath" value="${wtk.home}/appdb/RMS"/>
<!-- Define KJAR path installation for compressing the jar. -->
<property name="kjar" value="${kjarPath}/kjar.exe"/>
<!-- Define deployment properties. Assumes a Tomcat on Port 8080 and
the default login/password. Adjust this to your local settings. -->
<property name="deploy.target" value="http://localhost:8080/deployer"/>
<property name="deploy.login" value="admin"/>
<property name="deploy.password" value="admin"/>
</target>
<!-- =============================================== -->
<!-- USAGE -->
<!-- =============================================== -->
<target name="usage" depends="init">
<echo message=""/>
<echo message="J2ME Client build file"/>
<echo message="------------------------------------------------------"/>
<echo message=""/>
<echo message=" Available targets are :"/>
<echo message=""/>
<echo message=" usage -> help on usage"/>
<echo message=" build -> builds the project"/>
<echo message=" clean -> cleans up the build directory"/>
<echo message=" docs -> builds java-doc"/>
<echo message=" run -> builds and runs the test project"/>
<echo message=" debug -> builds and runs the test with debug active"/>
<echo message=" deploy -> deploy the MIDlet on the OTA server"/>
<echo message=" release -> builds release packages"/>
<echo message=" RMSDelete -> delete RMS path of WTK"/>
<echo message=" kjar -> compress the jar file"/>
<echo message=""/>
</target>
<!-- =============================================== -->
<!-- CLEAN -->
<!-- =============================================== -->
<target name="clean" depends="init">
<echo message="Clean output tree"/>
<delete dir="${dir.output}"/>
</target>
<!-- =============================================== -->
<!-- RMSDELETE -->
<!-- =============================================== -->
<target name="RMSDelete" depends="init">
<echo message="Delete RMS"/>
<delete dir="${RMSPath}"/>
</target>
<!-- =============================================== -->
<!-- REBUILD -->
<!-- =============================================== -->
<target name="rebuild" depends="clean, build"/>
<!-- =============================================== -->
<!-- BUILD -->
<!-- =============================================== -->
<target name="build" depends="compile">
<!--======= Jar up everything ========-->
<echo message="Packaging library"/>
<!-- peter: this sounds interesting -->
<!-- unjar src="${lib.jzlib}" dest="${dir.classes}"/ -->
<copy todir="${dir.classes}/res">
<fileset dir="${dir.res}" includes="*.png" />
<fileset dir="${dir.res}" includes="*.properties" />
<fileset dir="${dir.res}" includes="*.midi" />
</copy>
<wtkjad jadfile="${dir.output}/${jad.filename}.jad"
jarfile="${dir.output}/${jar.filename}.jar"
name="${jad.midlet-name}"
vendor="${jad.midlet-vendor}"
version="${jad.midlet-version}">
<midlet name="${jad.midlet-name}"
class="${jad.midlet-class}"
icon="${jad.midlet-icon}"/>
<!-- Always set -->
<!-- peter: question? why icon is double defined? -->
<attribute name="MIDlet-Icon" value="${jad.midlet-icon}" />
<attribute name="MIDlet-Data-Size" value="524288" />
<attribute name="MIDlet-Permissions" value="${jad.midlet-permissions}"/>
<!-- Set only if present in build.properties-->
<attribute name="ServerName" value="${jad.servername}"
if="jad.servername"/>
<attribute name="ServerPort" value="${jad.serverport}"
if="jad.serverport"/>
</wtkjad>
<wtkpackage jarfile="${dir.output}/${jar.filename}.jar"
jadfile="${dir.output}/${jad.filename}.jad"
obfuscate="${wtk.obfuscate}"
preverify="true" classpath="">
<!-- Package our newly compiled classes and resources.-->
<fileset dir="${dir.classes}"/>
</wtkpackage>
</target>
<!-- =============================================== -->
<!-- DEPLOY -->
<!-- =============================================== -->
<target name="deploy" depends="build">
<!-- Deploy the MIDlet suite -->
<wtkdeploy jarfile="${dir.output}/${jar.filename}.jar"
jadfile="${dir.output}/${jad.filename}.jad"
target="${deploy.target}"
login="${deploy.login}" password="${deploy.password}"/>
</target>
<!-- =============================================== -->
<!-- KJAR -->
<!-- =============================================== -->
<target name="kjar" depends="init">
<exec executable="${kjar}">
<arg value="-s"/>
<arg value="output/${jar.filename}.jar"/>
<arg value="output/${jad.filename}_comp.jar"/>
</exec>
</target>
<!-- =================================================================== -->
<!-- COMPILE -->
<!-- Compile the files -->
<!-- ====================================================================-->
<target name="compile" depends="init,clean">
<echo>Starting compile</echo>
<mkdir dir="${dir.classes}"/>
<echo>build from all the ${dir.src} to ${dir.classes}</echo>
<!-- peter: the new wtkbuild will hard coded wma.jar Grrr -->
<wtkbuild srcdir="${dir.src}"
destdir="${dir.classes}"
target="1.1" source="1.2" preverify="false"
debug="${wtk.debug}" listfiles="no" classpath="">
</wtkbuild>
</target>
<!-- =============================================== -->
<!-- RUN -->
<!-- =============================================== -->
<target name="run" depends="build">
<!-- Start the MIDlet suite -->
<wtkrun jadfile="${dir.output}/${jad.filename}.jad"
device="DefaultColorPhone" wait="true" >
</wtkrun>
</target>
<!-- =============================================== -->
<!-- DEBUG -->
<!-- =============================================== -->
<target name="debug" depends="init,build">
<!-- Start the MIDlet suite -->
<wtkrun jadfile="${dir.output}/${jad.filename}.jad"
device="DefaultColorPhone" wait="true" debug="5000"/>
</target>
<!-- =============================================== -->
<!-- SIGN -->
<!-- =============================================== -->
<target name="sign" depends="rebuild">
<!-- Sign the MIDlet suite -->
<!-- To avoid password in build files -->
<!--<input message="Enter ${keystore.alias} password:" addproperty="keystore.password"/>-->
<input message="Enter ${keystore.alias} password:" addproperty="keystore.password"/>
<java jar="${wtk.home}/bin/JADTool.jar" fork="true" failonerror="true">
<arg value="-addcert"/>
<arg value="-keystore"/>
<arg file="${keystore.path}/${keystore.file}"/>
<arg value="-alias"/>
<arg value="${keystore.alias}"/>
<arg value="-inputjad"/>
<arg file="${dir.output}/${jad.filename}.jad"/>
<arg value="-outputjad"/>
<arg file="${dir.output}/${jad.filename}.jad"/>
</java>
<java jar="${wtk.home}/bin/JADTool.jar" fork="true" failonerror="true">
<arg value="-addjarsig"/>
<arg value="-jarfile"/>
<arg file="${dir.output}/${jar.filename}.jar"/>
<arg value="-keystore"/>
<arg file="${keystore.path}/${keystore.file}"/>
<arg value="-keypass"/>
<arg value="${keystore.password}"/>
<arg value="-alias"/>
<arg value="${keystore.alias}"/>
<arg value="-inputjad"/>
<arg file="${dir.output}/${jad.filename}.jad"/>
<arg value="-outputjad"/>
<arg file="${dir.output}/${jad.filename}_t.jad"/>
</java>
<java jar="${wtk.home}/bin/JADTool.jar" fork="true" failonerror="true">
<arg line="-showcert -all"/>
<arg value="-inputjad"/>
<arg file="${dir.output}/${jad.filename}_t.jad"/>
</java>
</target>
</project>