BlackBerry Development Tools – JDE (and IDEA)

Posted October 22nd, 2008 by

Introduction

There are different tools that you can use for BlackBerry development – Eclipse Plugin and JDE. In this tutorial I will show you how to use the JDE in conjunction with IDEA as the primary IDE for BlackBerry development. Directions are provided on how to install and configure the JDE, then get started with a Hello World project, then deploy the project to the simulator and run it. The JDE is an IDE that BlackBerry created, and it’s really really old. Modern IDEs like IDEA, Eclipse, and NetBeans really put it shame. It’s good to see that BlackBerry is working on an Eclipse based IDE, and hopefully the JDE will be retired soon. I couldn’t stand to use the JDE by itself, which is why I do all my editing, compiling, refactoring in IDEA, and just use JDE to build my COD file and run it in the simulator, and occasionally use the debugger in the JDE. It’s really old looking and clunky, and just a pain to work with, when compared to IDEA. You can use Eclipse or NetBeans instead of IDEA if that’s your preference.

Books, devices, and accessories

If you’d like to buy BlackBerry devices, accessories, or user guides, from Amazon.com click here.

Using the BlackBerry JDE

You can download the JDE from BlackBerry’s website. Here’s a link to a video that shows you how to install the JDE. The JDE is old and clunky, but it works. The Eclipse Plugin is still in beta, as of this writing, and it’s not really usable. This is why using IDEA, Eclipse, or NetBeans, along with the JDE is the way to go.

Installation

Once you’ve downloaded the JDE installer, start it up and the following screenshots will guide you through the installation process:

Step 1 – run the installer.

Step 2 – select where you want to install the JDE (c:\blackberry\ide\jde is what I’ve chosen).

Step 3 – complete the install, then set the JDE_HOME environment variable to point to your JDE install directory (in my case c:\blackberry\ide\jde). Make sure that your JAVA_HOME environment variable is set as well. Now on to creating your first project.

Creating a project

Start the JDE. You will find that there’s a lot of documentation provided to you with the JDE under the Help menu (API reference, IDE help, Knowledgebase, etc).

Step 1 - Create a new workspace

In the BlackBerry IDE, projects are organized in a workspace. A workspace enables you to define dependencies between projects and to build and run related projects at the same time. You can also create unique build configurations that define which projects are built and run by default.  Each workspace is represented by a .jdw file. A project can belong to more than one workspace.

Under the File menu, click on New Workspace.

Step 1.1 - Name your workspace, and provide a directory in which it should be created; I’ve chosen c:\blackberry\dev\workspacefolder as the folder in which I want my workspace files to reside, and I’ve named the workspace MyWorkspaceFile. This is confusing. I thought that creating a new workspace would create a folder and .jdw file in that folder. Turns out that this not the case. So you have to specify the folder name in the “Create in this directory:” field, and the “Workspace name”.jdw that gets created in this folder. The string at the top of this dialog box is misleading… you’re not creating a folder by the name of “Workspace name”, rather it creates “Workspace name”.jdw in the “Create in this directory” folder. Whew! :)

Here’s a screenshot of my explorer window showing this:

Step 2 - Create a new project in this workspace.

Create a separate subfolder of the workspace folder for each project. If you type a folder name that does not exist, the BlackBerry IDE creates it. A project organizes the files that are required to produce an application or library, including source files, resource files, and graphics. A .jdp file represents a project file. When you compile a project, you compile its Java source files (.java) into a single .COD file. You create and manage projects in the main window using the Project menu. For each project, you can set properties, such as an application type, by right-clicking the project file (.jdp) in the Workspace window and using the shortcut menu.

Step 2.1 – Name your project.

Create a separate folder for your project files underneath the workspace folder. Again, this exercise is just as confusing as before (when we created the workspace folder). You have to specify the “Project name” and the “Create project in this directory” fields. Again, the dialog box is misleading; the path it shows on top of the dialog box is not right… So you have to specify a folder for your project in “Create project in this directory”. Then you have to specify the project file name (a .jdp file) that will be created for you. So a “Project name”.jdp file is created in the “Create project in this directory” folder. Whew!

Here’s a screenshot of my explorer window showing this:

image

I hope this makes sense. Here’s a screenshot of the JDE workspace:

Step 3 - Create a new source file.

This is really clunky and cumbersome to do, just as all the steps shown so far. So here goes. In the File menu, select New, then type in “HelloWorld.java” as the filename you want to create. Make sure that you have the “c:\blackberry\dev\myworkspacefolder\HelloWorldProjectFolder\src” as the Location. You would think that once this file is create, it’s automatically added to the project, right? Well, no; JDE does not do that for you. This must be the single most cumbersome, 90’s technology IDE I have used in a long while!

image

Copy and paste this into the source window:

/**
 * HelloWorld.java
 * Copyright (C) 2001-2004 Research In Motion Limited. All rights reserved.
 */

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;

public class HelloWorld extends UiApplication {
    public static void main(String[] args) {
        HelloWorld theApp = new HelloWorld();
        theApp.enterEventDispatcher();
    }
    public HelloWorld() {
        pushScreen(new HelloWorldScreen());
    }
}

final class HelloWorldScreen extends MainScreen {
    public HelloWorldScreen() {
        super();
        LabelField title = new LabelField("HelloWorld Sample", LabelField.ELLIPSIS
            | LabelField.USE_ALL_WIDTH);
        setTitle(title);
        add(new RichTextField("Hello World!"));
    }

    public boolean onClose() {
        Dialog.alert("Goodbye!");
        System.exit(0);
        return true;
    }
}

Step 3.1 - Add the source file to the project, manually!

Right click on the project “HelloWorldProjectFile” and select Add File to Project. Then select the HelloWorld.java file. This will add the .java file to your project. Now you will be able to compile it and run it. This disjointed workflow shows up pretty much everywhere in the JDE. It’s very old and cumbersome to use. I hope that RIM refines their Eclipse Plugin in very soon.

image

image

Customizing your project

Double clicking on the HelloWorldProject in the workspace window causes it’s property sheet to pop up. Here’s a screenshot of this:

You can also set the application icon for your project here, simply select a PNG file from your hard drive and it will be bundled in the COD file:

If you want to include other PNG files and assets in the COD file then add them to the project, just like you added the .java file to the project. So if you want some images to be included in the COD file then you have to add them to the project, otherwise JDE will not include them in the .COD file.

Running your code

To compile your code hit F7. To run it in the simulator, hit F5. This will start the simulator and load the .COD file, but it won’t run it automatically. You have to locate the app and run it (in the simulator). Also, if you make changes to your code, it won’t propagate them without restarting the simulator. So hit F7 again to build, and the JDE will prompt you if it should kill the simulator; say yes, and then hit F5 again (to run the simulator with your new changes). So you have to build each project manually, after making every change. There’s no auto compile.

When you hit F5, the JDE compiles your code and makes a .COD file, which it then loads into the simulator. If you use the default 9000 simulator, then you might wonder where your app has gone. Turns out that the recently loaded .COD file is placed in the Downloads folder, by default. You can move your app up to the top level folder and arrange it to where you want it on the home screen, so that you don’t have to go digging for it every time you fire up the simulator. Here’s where your apps are dumped by default:

Click on the Menu button, and you will be able to move this Downloads folder around:

downloads-01

BBDevMgr.exe out of control

Occasionally as you’re running your code in the simulator, you will find your CPU pegged to 100%. This happens when “BBDevMgr.exe” goes nuts and takes over your CPU. I’ve experienced this on more than one machine running Vista x64. I just kill it using my taskmanager or taskkill, without needing to restart the simulator. This problem happens whether you’re using the JDE or the Eclipse plugin. The following chart shows you how often I’ve experienced this problem in the past few weeks.

Restarting the simulator every time you make a change

Every time you make a change to your code, and you want to recompile and redeploy to the simulator, you will have to restart the simulator, before propagating your COD file to it. This takes a lot of time and is really annoying to have to do very frequently. The Android simulator is much better than Fledge in this respect, since you can propagate your changes without having to restart the simulator (which takes time). I’m going to publish another tutorial just on the simulator (called Fledge).

Using IDEA with JDE

Once JDE has been installed, you can create a new IDEA project with existing sources and save it in the same project folder as your JDE project. You have to tell IDEA where to find the net_rim_api.jar file. Create a new project library in IDEA using the following settings (assuming your JDE_HOME is c:\blackberry\ide\jde):

  • javadocs are at – c:\blackberry\ide\jde\docs\api
  • classes are at – c:\blackbery\ide\jde\lib\net_rim_api.jar

Syncing with JDE

If you create new files (classes, interfaces, PNG images, etc) in your IDEA project, or if you refactor (move/rename) existing files and packages, you have to go back into the JDE and remove them from the project, and/or add the new files into the project. This is pretty cumbersome! The good news is that if you try and build your un-sync’d project in the JDE, it will complain that there are errors, and you can sync things then.

Comments and feedback

To share your thoughts on this tutorial click here.


Comments are closed.