1. Add a "run" target, support running both blackberry and regular J2ME simulator.
<target name="run" depends="init,jar,bb-run,cldc-run"> <target name="cldc-run" unless="do.rapc" > <nb-run jadfile="${dist.dir}/${dist.jad}" jarfile="${dist.dir}/${dist.jar}" jadurl="${dist.jad.url}" device="${platform.device}" platformhome="${platform.home}" platformtype="${platform.type}" execmethod="${run.method}" securitydomain="${evaluated.run.security.domain}" commandline="${platform.runcommandline}" classpath="${platform.bootclasspath}:${dist.dir}/${dist.jar}" cmdoptions="${run.cmd.options}"/> </target> <target name="bb-run" depends="copyBBSimulator" if="do.rapc"> <exec os="Windows NT Windows 95 Windows 98 Windows 2000 Windows XP" dir="${platform.home}/simulator" executable="${platform.home}/simulator/${platform.device}.bat" failonerror="true" resolveExecutable="true"/> </target>The above code snipplet means, when user press "run" button in NetBeans IDE, if the current configuration is blackberry, then launch the blackberry simulator, else launch the regular J2ME simulator.
2. Separate the blackberry specific ant targets into aother build script file, make the build file generic and easier to use.
At the beginning I tried to put all the targets in a separate file: bb-build.xml, then import it in the build.xml, but I found the netbeans custom targets like post-init, post-jar are not called, it seems these targets needs to be explicit specified in the build.xml.
I found another solution - embedding the xml snippet in the build.xml using XML entity, based on this link:
for exmaple, like this:
<!DOCTYPE project [ <!ENTITY bb-common SYSTEM "bb-build.xml"> ]> &bb-common;The above snippet is equivlent of copying the code from bb-build.xml into build.xml.
Benefits:
The new refactored build script becomes generic, does not specific to lwuit project, can apply to any blackberry CLDC app.
I attach the full build script here, and you can use them as template for your blackberry build script in your NetBeans project.
1) build.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE project [ <!ENTITY bb-common SYSTEM "bb-build.xml"> ]> <project name="myApp" default="jar" basedir="."> <description>Builds, tests, and runs the project .</description> <import file="nbproject/build-impl.xml"/> <property name="app.title" value="myApp" /> <property name="app.version" value="1" /> <property name="app.icon" value="/icon.png" /> <property name="app.vendor" value="foo" /> &bb-common; </project>
2) bb-build.xml, the blackberry build script snippet
<target name="post-init"> <available file="${platform.home}/bin/rapc.exe" property="do.rapc" /> <condition property="jpda.port" value="8000"> <isset property="do.rapc"> </isset> </condition> </target> <target name="post-jar" if="do.rapc"> <antcall target="bbbuild" /> </target> <target name="run" depends="init,jar,bb-run,cldc-run"> </target> <target name="cldc-run" unless="do.rapc" > <nb-run jadfile="${dist.dir}/${dist.jad}" jarfile="${dist.dir}/${dist.jar}" jadurl="${dist.jad.url}" device="${platform.device}" platformhome="${platform.home}" platformtype="${platform.type}" execmethod="${run.method}" securitydomain="${evaluated.run.security.domain}" commandline="${platform.runcommandline}" classpath="${platform.bootclasspath}:${dist.dir}/${dist.jar}" cmdoptions="${run.cmd.options}"/> </target> <target name="post-clean"> <delete failonerror="false"> <fileset dir="${platform.home}/simulator"> <include name="**/${name}.*"> </include> </fileset> </delete> </target> <typedef resource="bb-ant-defs.xml" classpath="bb-ant-tools.jar" /> <target name="bbbuild" description="blackberry build" depends="init" if="do.rapc"> <echo message="rapc build, dir=${dist.dir}"></echo> <mkdir dir="${dist.dir}/bbant" /> <rapc verbose="true" output="${name}" jdehome="${platform.home}" import="${platform.bootclasspath}" destdir="${dist.dir}/bbant/" noconvert="true"> <src> <fileset file="${dist.dir}/${dist.jar}" /> </src> <jdp title="${app.title}" vendor="${app.vendor}" version="${app.version}" type="cldc" icon="${app.icon}" > </jdp> </rapc> <!-- sigtool jdehome="C:Program FilesResearch In MotionBlackBerry JDE 4.7.0" codfile="${dist.dir}/bbant/${name}.cod" password="" / --> <alx destdir="${dist.dir}/bbant" filename="${name}.alx"> <application id="${app.title}"> <codset> <fileset dir="${dist.dir}/bbant" includes="*.cod"> </fileset> </codset> </application> </alx> <mkdir dir="${dist.dir}/bbant-final" /> <jadtool input="${dist.dir}/bbant/${dist.jad}" destdir="${dist.dir}/bbant-final"> <fileset dir="${dist.dir}/bbant" includes="*.cod"> </fileset> </jadtool> </target> <target name="copyBBSimulator" if="do.rapc"> <copy todir="${platform.home}/simulator" verbose="true"> <fileset dir="${dist.dir}/bbant"> <include name="*.cod"/> <include name="*.jad" /> </fileset> </copy> </target> <target name="bb-run" depends="copyBBSimulator" if="do.rapc"> <exec os="Windows NT Windows 95 Windows 98 Windows 2000 Windows XP" dir="${platform.home}/simulator" executable="${platform.home}/simulator/${platform.device}.bat" failonerror="true" resolveExecutable="true"/> </target>
Next Step:
Add a target support debugging blackberry Application inside the NetBeans IDE.