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


Quick Overview of BlackBerry Files

Lets briefly cover the files that you will encounter when creating a BlackBerry application:

  • .java - your application's source files.
  • .jad - the Java Application Descriptor (JAD).
  • .rapc - same as a JAD file, but with BlackBerry-specific entries. In our Ant script, we won't use a .rapc but instead use standard .jad files.
  • .jar - Java Archive, which is the standard packaging file format for MIDP 1.0 applications.
  • .cod - standard (native) packaging file format that executes on the BlackBerry device.
  • .alx - application loader file, used by the Application Loader tool, which is part of the BlackBerry Desktop Software, to load new applications onto the handheld. Use the IDE to generate .alx files for your projects. For more information, see About .alx files.
  • .mak - a Makefile as the one in Listing 1.

It is important to emphasize that what gets loaded into BlackBerry handsets are .cod files. If you have a MIDlet, it must first be converted to a .cod package.

The BlackBerry RAPC Compiler

RAPC is the command line compiler that is used to compile .java files into .cod files that are loaded onto the handheld. Figure 2 illustrates the input and outputs of the RAPC compiler:

Figure 2. - Using the RAPC Compiler

Inputs to the RAPC compiler are:

  1. Source .java files or input JAR file.
  2. JAD file for the application.
  3. List of import libraries such as the RIM APIs and dependant 3rd party libraries.
  4. Codename to use for the application - must match the .jar file name.
  5. The -midlet flag - optional flag set if building a MIDlet instead of a CLDC application. You also need to properly populate the standard MIDlet-* JAD and MANIFEST attributes

For example, the RAPC compiler's usage is as follows:

    rapc.exe import=C:\BlackBerryJDE3.7\lib\net_rim_api.jar codename=MyClientApp MyClientApp.jad MyClientApp.jar

The RAPC compiler generates a .cod file and a modified JAD file with BlackBerry specific entries added to it, such as the size of the .cod file, creation time, signature, and other. Listing 2 shows a JAD file for a BlackBerry CLDC application:

Listing 2. - Sample JAD file for a BlackBerry CLDC Application

Manifest-Version: 1.0
MIDlet-Version: 0.0
MIDlet-Jar-Size: 205354
MicroEdition-Configuration: CLDC-1.0
MIDlet-Jar-URL: MyClientApp.jar
MIDlet-Name: MyClientApp
MIDlet-1: ,,
MicroEdition-Profile: MIDP-1.0
MIDlet-Vendor: J2MEDeveloper.com
RIM-COD-Module-Dependencies: net_rim_cldc,net_rim_os
RIM-MIDlet-Flags-1: 0
RIM-COD-Module-Name: MyClientApp
RIM-COD-Size: 88616
RIM-COD-Creation-Time: 1089855050
RIM-MIDlet-Position-1: 0
RIM-COD-URL: MyClientApp.cod
RIM-MIDlet-NameResourceId-1: 0
RIM-COD-SHA1: 89 bd de fe 1d 07 3a 0d 1a 15 23 ea 94 57 c5 fa 0f 2f 1f fe
RIM-MIDlet-NameResourceBundle-1:             

***Note that BlackBerry JDE and related build tools are only targeted at the Microsoft Windows NT, 2000 and XP environments.

Using Apache Ant for Blackberry Builds

There are plenty of great introductions to Ant, so here we will briefly cover the main concepts. Please refer to the resources section for a list of Ant resources.

Apache Ant is a build tool written in Java. An Ant script is an XML file that defines interdependent build tasks for a project such as "clean directories", "java compile", and "JAR classes". For our Ant scripts we leverage Antenna as much as possible. Antenna is a set of Ant tasks for building wireless Java applications targeted at MIDP; this simplifies many Ant script tasks which otherwise we would have to write ourselves.

Structuring the Project

A proper directory structure for your project will help you maintain your project's files neatly organized. Figure 3 illustrates a project organization that I have found useful; this directory structure is used by the finished Ant script I'll present below:

Figure 3. Our Project Directory Structure

The project's root directory contains the build.xml file as well as other support files such as our JAD and MANIFEST template files - we use these templates to generate our final (properly) populated JAD and MANIFEST files. The rest of our directories are for our compiled classes, build output, the source code, resource files, and support libraries.


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.