BlackBerry Development Tools – Eclipse Plugin (in beta) – Tutorial

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 Eclipse Plugin as your IDE for BlackBerry development. Directions are provided on how to install and configure the Eclipse Plugin, then get started with a Hello World project, then deploy the project to the simulator and run it.

Books, devices, and accessories

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

Using Eclipse Plugin (Beta)

You can download the Eclipse Plugin from from BlackBerry’s website. Here’s a video how to install the Eclipse plugin. The Eclipse environment is still in beta and has lots of quirks and limitations. For example, if you’re planning on including images (PNG files) in your BlackBerry projects (COD files) then the Eclipse plugin will not work for you. However, it’s quite fast, and modern, compared to the JDE. The following are some quick steps to get started with using the Eclipse Plugin.

Installation

The installer installs Eclipse 3.x if you don’t have Eclipse, or point it to a directory where it exists, and it will just install the BlackBerry plugin for that Eclipse instance. I let the installer install it’s own Eclipse environment, and the plugin. Here are some screenshots of the installation process:

  1. Install Eclipse and the plugin to c:\blackberry\ide\eclipse
  2. Complete the installation:
  3. On to creating your first project:

Creating a project

Launch Eclipse by running eclipse.exe in c:\blackberry\ide\eclipse.

Step 1 – Create the workspace

Step 2 – On first run, after you give it the workspace, from Blackberry menu, select Configure BlackBerry Workspace, then just click Yes.

Step 2.1 – Click OK.

Step 3 – Under the File menu, select New -> Project. Then select Blackberry Project.

Step 3.1 – Give it a name, eg: “FirstProject”, then click on Finish.

Step 4 – Create a new Java class

Step 4.1 – Call the class “HelloWorld’, and click Finish.

Copy this code into the source file:

/**
 * 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 5 – Set project properties, go to Project -> Properties -> BlackBerry Project Properties, and set all the data (you can set the app icon here):

Step 5.1 – Go to the Resources tab, and you will be able to add an app icon to your project. You can read more about BlackBerry icon sizes and formats here. Click on OK after you’ve made an icon selection (if you want your app to have an icon on the BlackBerry home screen).

Step 6 – The javadoc location is automatically set in Window -> Preferences -> Blackberry JDE -> Installed Components. The default location is – C:\blackberry\ide\eclipse\plugins\net.rim.eide.componentpack4.3.0_4.3.0.8\components\docs\api. Changing anything here, recreates the workspace files.

Step 7 – to run the HelloWorld project, just select Run -> Run, then select the BlackBerry Simulator, then click OK.

Step 7.1 – This launches the default simulator. Click on the Menu button, and you will see the newly added HelloWorld app in there.

Limitations and problems

Images

As of this writing, the Eclipse Plugin is still in Beta, and has some problems. If you want image files (PNG, JPEG, etc) to be available to your BlackBerry app (and end up in the COD file), then you will encounter problems with the plugin, which does not recognize any images that you add to your project.

Need more help? developerlife.com offers training courses to empower you, and consulting services to enable you.

Adding files to your project manually

If you add external sources or files that you want included in your BlackBerry project, you have to right click on the HelloWorld project, and invoke the “Add File to BlackBerry Project” menu, which will make these files available to rapc.exe when it’s run to compile your code and generate your COD file.

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).


Comments are closed.