Wednesday, November 14, 2007

Blackberry Development Using NetBeans Mobility Pack

With the RIM Blackberry JDE 4.1, you can now build Java ME applications for Blackberry devices using NetBeans Mobility Pack for CLDC/MIDP 5.5.


Before you begin, you need to install the following software on your computer:

Setting Up for BlackBerry Development

To set up your NetBeans IDE for Blackberry development, you need to add the Blackberry JDE as a custom platform emulator because there are utilities distributed with the JDE that are not distributed with its emulators.

To do this, you perform three steps:

  1. Add the RIM Blackberry JDE as a custom emulator
  2. Create a Blackberry project
  3. Set the Blackberry as the default device emulator

Adding the RIM Blackberry JDE as a Custom Emulator

To begin, you must register the RIM Blackberry emulator using the Java Platform Manager:

  1. Select Tools > Java Platform Manager from the top navigation bar.
  2. Click the Add Platform button.
  3. Select Custom Java Micro Edition Platform Emulator. Click Next.
  4. The Platform Home should be JDE installation directory (C:\Program Files\Research In Motion\BlackBerry JDE 4.1.0).
  5. You can enter whatever you want for the Platform Name.
  6. Set Device Name to one of the supported devices: 7100g, 7100r, 7100t, 7100v, 7100x, 7250, 7290, 7520,
  7. Keep the Preverify Command as it is.
  8. Modify the Execution and Debugger Commands as shown:
    • Execution Command: cmd /C "cd /D {platformhome}{/}simulator&{device}"
    • Debugger Command: cmd /C "cd /D {platformhome}{/}bin&jdwp"
    Click Next.
  9. The Bootstrap Libraries panel displays a long list of jar files. Select all of the listed files except net_rim_api.jar and click Remove. Click Next.
    Note: If the net_rim_api.jar is not in the list, Click the Add button, and type in or navigate to C:\Program Files\Research In Motion\blackberry JDE 4.1.0\lib\net_rim_api.jar and click Open.
    Then click Next.
  10. In the Sources and JavaDoc panel, click the Add button next to the JavaDoc window and type in or navigate to: C:\Program Files\Research In Motion\BlackBerry JDE 4.1.0\docs\api\. The Java Platform Manager should look like the following graphic:

Click Finish, then click Close.

Creating a Blackberry Project

Next, you create a project for your application:

  1. Choose File > New Project.
  2. Under Categories, choose Mobile. Under Projects, choose Mobile Application. click Next.
  3. Give the project a name, for example MobileApplication2.
    If you do not want a sample MIDlet created for your project, uncheck the "Create Hello MIDlet" check box.
  4. Click Finish to create the Project.
  5. Select the Files Tab in the Explorer window and open the project's build.xml file. Add this (below Image)fragment of code right before the tag at the bottom of the file.
  6. If you would like to extend net.rim.device.api.ui.UiApplication instead of standard MIDlets in your project, then:
  • Remove the highlighted argument line from the build.xml script above.
  • Ignore the warnings in Project Properties / Application Descriptor / MIDlets category when adding a class that does not extend MIDlet.
7. From the Files tab, create a new Empty file, called .alx, and save it into your project folder (on the same level as build.xml!) with the content(below Image). Change the names of course to reflect your application. This is a special file required by Blackberry devices to identify the application details.

Set the Blackberry as the Default Device Emulator

Now you're ready to set the default configuration to emulate a Blackberry device:

  1. Right-click on the project and choose Properties.
  2. In the Platform Properties:
    • Choose Blackberry 4.1 from the Emulator Platform drop-down menu.
    • Choose the Blackberry device emulator from the Device drop-down menu.

At this point, you are ready to write code, build, run, execute, and debug your MIDlet for the BlackBerry.

Note: Once you build your project and the emulator launches, you will need to scroll to the icon for your application, which will be on the main phone screen when the emulator comes up. You can use the arrow keys or click the scroll wheel on the emulator image to navigate to your application icon.


Unknown said...

I followed these instructions exactly, and when done, debugging does not work. The simulator opens with my program and I can step over statements, but I can not step into methods. Also the values of variables is not shown, only the object id is shown.
Debugging works fine in the Blackberry JDE.

Raja N said...

Press F8 instend of F7 it will be working.....

hasija said...

Is their any way to run different blackberry project configurations in netbeans? The build.xml file here supports only the default configurations. can you please provide the changes in build.xml file to run the project configurations?

sonson said...

I just followed all the directions on the Netbeans site on how to create an app and debug it inside the Blackberry simulator.

It works fine, but ONLY if I chose the option to "Create Hello MIDlet" in the Netbeans wizard when creating the application.

If I don't check that box and I create an empty project, my application (which is nothing but the from the official Blackberry samples in the 4.2 SDK) does not show up on the device emulator and I get a few warnings from the build process such as:

1) Updating application descriptor: C:\Dev\mobile\blackberry_4.2\ITCoverage\dist\ITCoverage.jad
Application descriptor does not declare any MIDlet. Direct execution is not allowed.

2) Warning!: method 'com.rim.samples.device.ITCoverage.ITCoverage.main(String[])' not invoked.

Surely I should be able to create non MIDlet application from Netbeans and have it run properly right? Any suggestions on what I am doing wrong?