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 preprocessorIf
If, else, end if block:
is defined, then the code between
elseis executed; otherwise,
#endifis executed. The
elsesection is not mandatory.
If not, else, end if block:
#ifndefis the opposite of
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 http://na.blackberry.com/eng/developers/javaappdev/javaeclipseplug.jsp.
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:
- Open the JDP file with an editor.
- Go to the line that starts with Options.
- At the end of the line, add -define
;as in the following example: ;…;
-definestatement 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.