If you look at the version
Ant target task,
you will notice that it preprocesses the JAD and MANIFEST files,
adding version information. Listings 4 and 5 show the template
files, and their final state after versioning and packaging.
Listing 4a. Original JAD Template File
MIDlet-Name: @midletName@ MIDlet-Version: @buildVer@ MIDlet-Vendor: J2MEDeveloper MIDlet-Description: MicroEdition-Profile: MIDP-1.0 MicroEdition-Configuration: CLDC-1.0 MIDlet-Jar-URL: @jarName@ MIDlet-Jar-Size: @jarSize@ MIDlet-1: ,,
Listing 4b. Final JAD File - Versioned and with BlackBerry-specific Information
Manifest-Version: 1.0 MIDlet-Jar-Size: 160220 MIDlet-1: ,, MIDlet-Jar-URL: MyAppClient.jar MicroEdition-Configuration: CLDC-1.0 MIDlet-Version: 1.0 MIDlet-Name: MyAppClient <P> MIDlet-Description: MIDlet-Vendor: J2MEDeveloper MicroEdition-Profile: MIDP-1.0 RIM-COD-Module-Name: MyAppClient RIM-COD-Module-Dependencies: net_rim_cldc,net_rim_os RIM-COD-Creation-Time: 1092667276 RIM-COD-URL: MyAppClient.cod RIM-COD-SHA1: a1 82 6f e6 1a 62 80 b8 8b 63 6c 54 69 11 0b 4b 63 78 05 84 RIM-COD-Size: 92928
Listing 5a. Original MANIFEST Template File
MIDlet-Name: @midletName@ MIDlet-Version: @buildVer@ MIDlet-Vendor: J2MEDeveloper MIDlet-Description: MicroEdition-Configuration: CLDC-1.0 MicroEdition-Profile: MIDP-1.0 MIDlet-1: , ,
Listing 5b. Final Versioned MANIFEST File
Manifest-Version: 1.0 Ant-Version: Apache Ant 1.6.1 Created-By: 1.4.2-b28 (Sun Microsystems Inc.) MIDlet-Name: MyAppClient MIDlet-Version: 1.0 MIDlet-Vendor: J2MEDeveloper MIDlet-Description: MicroEdition-Configuration: CLDC-1.0 MicroEdition-Profile: MIDP-1.0 MIDlet-1: , ,
Running Our Application from Within Ant
Running our application in the simulator requires us to first copy the generated files into the simulator directory, then invoke the appropriate simulator with the appropriate arguments. For this we will add two more steps to our Ant script:
- Update the BlackBerry simulator file system, and
- Run our application in the simulator.
The simulator to invoke will depend on which simulators you have installed on
your computer. To write our run build task for a particular handset the easiest thing to do is to open the appropriate batch file for the simulator
for the handset of interest (found in the simulator directory), and
just transfer the input arguments into the Ant task. For example, for the the
7500 handset we would open the OS7500.bat batch file. We will see
that the batch file invokes the osloader.exe
passing
the os7500.dll as one of its argument. The usage of the osloader.exe command is a follows:
osloader.exe Os7500.dll /wi /app:DisableRegistration /rsim=0x20000001 /F16384
/H1119264 /GRES=240x160x16 /rport=19780 /rport=8205 jvm.dll
If you look at Listing 6 below, you will see how our run
Ant task mirrors the line
above:
Listing 6. Ant Tasks to Run Your Application
<target <b>name="updatesim"</b> description="Update BlackBerry Simulator"> <copy todir="${blackberry.simulator.path}/"> <fileset dir="output/tocod"/> </copy> </target> <P> <!-- The following same arguments were in the OS7500.bat file: osloader.exe Os7500.dll /wi /app:DisableRegistration /rsim=0x20000001 /F16384 /H1119264 /GRES=240x160x16 /rport=19780 /rport=8205 jvm.dll --> <target <b>name="run"</b> description="Run"> <exec dir="${blackberry.simulator.path}" executable="${blackberry.simulator.path}/osloader.exe"> <arg line=" Os7500.dll /wi " /> <arg line=" /wi " /> <arg line=" /app:DisableRegistration " /> <arg line=" /rsim=0x20000001 " /> <arg line=" /F16384 " /> <arg line=" /H1119264 " /> <arg line=" /GRES=240x160x16 " /> <arg line=" /rport=19780 " /> <arg line=" /rport=8205 " /> <arg line=" jvm.dll " /> </exec> </target>
In Summary
In this article we have covered the JDE's build capabilities. We also covered Ant, its benefits, and how to use if for your BlackBerry build process. Ant is a very powerful build tool, and with this article you should now have enough information to support Ant for all your BlackBerry builds, build your application from IDEs such as IDEA, Eclipse and Netbeans, and integrate your BlackBerry build into your overall build process.
Resources
- Apache Ant
- Notes of BlackBerry Development
- The Antenna project
C. Enrique Ortiz is a software architect and developer, and a mobile/wireless technologist and writer. He is author or co-author of many publications, a co-designer of Sun Microsystems' the Mobile Java Developer Certification Exam, and has been an active participant in the wireless Java community and of various J2ME expert groups.