Wednesday, May 12, 2010

How To - Use the preprocessor in BlackBerry JDE

RIM Application Program Compiler (RAPC) supports a few basic preprocessor directives. The directives can be used to take advantage of features available in later BlackBerry smartphones and builds without fragmenting into multiple code lines, or to make it easy to remove debug output for final versions.
The following directives are supported:

Enable the preprocessor

If, else, end if block:


If is defined, then the code between #ifdef and else is executed; otherwise, #else to #endif is executed. The else section is not mandatory.
If not, else, end if block:


#ifndef is the opposite of #ifdef. If is not defined, the code is executed.
When using the BlackBerry JDE Plug-in for Eclipse or BlackBerry JDE 4.7 and later, you can set preprocessor defines in the Project Properties window, on the Compile tab as shown in the following image:

If the Preprocessor defines box is not present in Eclipse®, update the BlackBerry JDE Plug-in for Eclipse to the latest available version. If you have not configured Eclipse to use the BlackBerry JDE Plug-in for Eclipse update site, this can be accomplished by following the steps found at
To use the preprocessor in BlackBerry JDE prior to version 4.7, you must manually add it to the Java® development project (JDP) file. To do this, complete the following steps:
  1. Open the JDP file with an editor.
  2. Go to the line that starts with Options.
  3. At the end of the line, add -define ;;…; as in the following example:
  4. Options=-quiet -define=FOO;PREPROCESSOR
    The -define statement is simply an argument passed to the RAPC. Therefore, you can use it with your own command line build scripts. This functionality has been present since RAPC version 4.0.
    If you use the preprocessor, make sure at least one definition is defined, typically PREPROCESSOR, or it will not engage.

1 comment:

Sirena said...

Thanks for this wonderful article. M Sirena Alexander working with BREW Application Development and it is very useful to me.