Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

BlackBerry Development: Using Apache Ant


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:

  1. Update the BlackBerry simulator file system, and
  2. 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

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.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.