Developing BlackBerry Applications Using Eclipse

Creating BlackBerry applications is exciting, but often difficult to get started. Once you've gotten a basic Hello World application under your belt you might feel a bit constrained by the feature set offered in the BlackBerry Java Development Environment from RIM. In this article we'll explore creating your BlackBerry applications in the defacto-standard IDE - Eclipse.

Step 1 - Installation

Download and install the BlackBerry Java Development Environment. According to RIM you can download their component package only, but trust us, you'll want the full IDE. We used version 4.2.1 but feel free to substitute their latest release.

Download and install Eclipse. For this article we've download Eclipse 3.2.2, but you should be fine with the latest stable version. We also noted that it's useful to install in C:\Eclipse (we found issues when compiling to paths using long filenames)

If you haven't already, download and install the latest Java Runtime from Sun.

Step 2 - Activate the Java Debug Wire Protocol

Before another application can begin using JDWP there are a few pre-steps. First you'll have to debug at least once in the BlackBerry JDE. You can do this by opening the BlackBerry JDE under:

Start > All Programs > Research In Motion > BlackBerry JDE 4.x.x > JDE

and then click Debug > Go (F5) inside the JDE.

From that point on whenever you want to start debugging you can click:

Start > All Programs > Research In Motion > BlackBerry JDE 4.x.x > JDWP

Step 3 - Creating a new BlackBerry project

Open up Eclipse and create a new workspace, if needed. As noted previously, it's advised to place your workspace in a directory with a short path (like c:\bbdev or similar). Don't create a project yet.

Workspace Preferences

  1. Click Window -> Preferences
  2. Expand the Java tree item
  3. Select Installed JRE's
  4. Click the Add button
  5. In the Add JRE window, enter a name such as "BlackBerry JRE" and browse to your JRE directory (in our example we're using C:\Program Files\Java\jdk1.6.0_01\jre)
  6. Remove all JAR files that were automatically added
  7. Click the Add External JARs button
  8. Browse to the lib directory of the BlackBerry JDE installation (For us it is located in C:\Program Files\Research In Motion\JDE 4.2.1\lib) and select the net_rim_api.jar. Click the Open Button
  9. Select the jar file that you just added, and click the Javadoc location button.
  10. Click the Browse button and navigate to the docs/api directory of your BlackBerry JDE installation (For us it is located in file:/C:/Program Files/Research In Motion/BlackBerry JDE 4.2.1/docs/api/) then click Ok.
  11. On the New JRE window, click Ok to close it.
  12. Make the new JRE the default, and click Ok to close the Preferences Window.

Project Creation

  1. Create a new Java project (File -> New -> Project), making sure that the default JRE is the one you added in the previous step.
  2. Accept the default settings by clicking Finish

Builder Settings

  1. Navigate to the project properties (Project -> Properties) and select the Builders section
  2. Click the New button
  3. Select the Program option and click Ok
  4. Select a name, such as BlackBerry builder
  5. In the Location field, click Browse File System, and locate the bin directory of your BlackBerry JDE installation (in our example this is C:\Program Files\Research In Motion\BlackBerry JDE 4.2.1\bin)
  6. Select the rapc.exe file
  7. Click the Open button.
  8. In the Working Directory field, click the Variables button
  9. In the Select Variable window, click on build project
  10. Click Ok
  11. In the arguments text box, add the following: -quiet [file list] import=[RIM jar location] codename=[project path] (in our example the full arguments box looks like -quiet c:\bbdev\Test\*.java import="c:\program files\research in motion\jde 4.2.1\lib\net_rim_api.jar" codename=c:\bbdev\Test)
  12. Select the Build Options tab
  13. In the Run the builder section, check that the following are selected: After a Clean, During Manual Builds, and During auto builds
  14. Click Ok
  15. Click Ok to close the properties window

Update the debugger settings

  1. Click Window -> Preferences
  2. Expand the Java item
  3. Select the Debug option
  4. In the Communication section, change Debugger timeout field to a larger amount, such as 30000
  5. If you experience problems connecting to the debugger, increase this amount

Debugging Using JDWP

  1. From Eclipse select Run -> Debug...
  2. Select Remote Java Application
  3. Click the New icon (or double click Remote Java Application)
  4. Your application should automatically be created
  5. Click Close
  6. Start the JDWP
  7. Click Run ->Debug
  8. Under the Remote Java Application section, select your application and click Debug

Tips & Tricks

Here are a couple of tricks that I've used to help me create applications. If you have your own please reply to the thread and I'll update:

  1. Create batch files for each simulator that you want to connect to and add them under External Tools - mine take the compiled code, copies it to the simulator directory and launches the simulator. This lets me rapidly test an app out on a variety of devices

 

Trackback URL for this post:

http://blackberry.developercommunity.com/trackback/198

Comments

tOMPSON's picture

Nice tutorial, was able to set up my system to compile a small Hello World application. You should mention that the Java Compliance level has to be set to 1.4.

I have one problem: When I start the debugger the device simulator starts but my application is not deployed to the device. I tried to add the .cod file manually but I did not work too. Am I missing something?

Community Staff
Wizard's picture

I wrote a small batch file (you remember those from the 80's right?) that copied my cod files into the simulator directory.  When the simulator starts it scans that directory.

There might be a better way, but it works for me :) 

Hi,

I'm having problem.
I'm not seeing follow in Debugging Using JDWP section.
------------------------------
From Eclipse select Run -> Debug...
Select Remote Java Application
------------------------------
I'm using eclipse 3.4 which is new version.
Can you help me on this?

Thanks,
Dk