Thursday, November 15, 2007

J2ME Development with NetBeans + J2mePolish + BlackBerry


Working with J2ME, NetBeans, NetBeans Mobility Pack, J2mePolish and BlackBerry is not an easy task for sure. After spending nights I've managed to put up a workable development environment "that works". For all those out there, who are working on the same or planning to work in near future, following is a step by step procedure which will be helpful in setting up things quickly.

Pre-Requisites:

  1. NetBeans 5.5
    1. Download: http://www.netbeans.info/downloads/index.php?rs=11
    2. Installation Instructions: http://www.netbeans.org/community/releases/55/install.html

  2. NetBeans Mobility Pack for CLDC
    1. Download: http://www.netbeans.info/downloads/index.php?p=4
    2. Installation Instructions: http://www.netbeans.org/community/releases/55/1/mobility-install.html

  3. J2mePolish 2.0 RC4
    1. Download: http://www.j2mepolish.org/download.html
    2. Installation Instructions: http://www.j2mepolish.org/docs/install.html

  4. BlackBerry JDE 4.2.1
    1. Download: https://www.blackberry.com/CorpDevZone/sd2integration.do?file=https://www.blackberry.com/Downloads/contactFormPreload.do?code=00EC53C4682D36F5C4359F4AE7BD7BA1&dl=082B317A6A9BDCF567A66673A23C2763
    2. NOTE: You need to sign in to download (Sign up is Free)
    3. Installation Instructions: Follow the installation wizard instructions.
  5. BlackBerry Email and MDS Services Simulator
    1. Download: https://www.blackberry.com/CorpDevZone/sd2integration.do?file=https://www.blackberry.com/Downloads/contactFormPreload.do?code=00EC53C4682D36F5C4359F4AE7BD7BA1&dl=A863E2C10B7E517A09C80F83418E8B2D
    2. NOTE: You need to sign in to download (Sign up is Free)
    3. Installation Instructions: Follow the installation wizard instructions.

Configuration:

  1. Adding BlackBerry JDE 4.2.1 as a Custom Emulator:
    1. Open NetBeans IDE
    2. Select Tools > Java Platform Manager
    3. Click the Add Platform button
    4. Select Custom Java Micro Edition Platform Emulator. Click Next.
    5. Browse BlackBerry JDE 4.2.1 installation directory (C:\Program Files\Research In Motion\BlackBerry JDE 4.2.1)
    6. Enter desired Platform Name (RIM BlackBerry JDE 4.2.1)
    7. Enter desired Device Name (8800)
    8. Keep the Preverify command as it is
    9. Modify Execution and Debugger command as follows:
      1. Execution Command:
        cmd /C "cd /D {platformhome}{/}simulator&{device}"
      2. Debugger Command:
        cmd /C "cd /D {platformhome}{/}bin&jdwp"
    10. Click Next
    11. Select all listed files except net_rim_api.jar and click Remove.
    12. Click Next.
    13. Click the Add button next to JavaDoc panel and browse to /docs/api folder inside the BlackBerry JDE Installation directory (C:\Program Files\Research In Motion\BlackBerry JDE 4.2.1\docs\api)
    14. Click Finish and then click Close.

Creating a New Project:

  1. Select File > New Project
  2. Click Next
  3. Enter Project Name, select Project Location and click Next
  4. Select desired Configurations, Profiles/Platforms, Libraries and Devices. Click Next.
  5. Leave Specify Project Properties panel as it is and click Next.
  6. Click on the Files tab and create /dist and /source/src folders under the project root folder.
  7. Click on the Projects tab, then right click on TestProject and select New > Java Package
  8. From the Projects tab, right click on newly created test package and select New > Midlet
  9. Enter desired Midlet Name, Midlet Class Name and select Package. Click Finish.
  10. From the Projects tab, right click on TestProject and select Properties.
  11. From the Category list, click on Platform, select BlackBerry JDE 4.2.1 from the Emulator Platform drop down list and select Ok.
  12. From the Category list, select MIDlets under Application Descriptor and make sure TestMidlet entry is there.
  13. From the Category list, select Libraries & Resources and make sure enough-j2mepolish-client.jar is there with its correct path. For example, C:\Program Files\J2ME-Polish\import\enough-j2mepolish-client.jar. You may witness incorrect path like C:\Program Files\J2ME-Polish\import\C:\Program Files\J2ME-Polish\import\enough-j2mepolish-client.jar
  14. Click Ok.
  15. From the Files tab, double click on build.xml to open it in editor.
  16. Enter two new properties blackberry.home and polish.blackberry.verbose in the build.xml file as show below:
  17. Update general settings to match your desired settings
  18. Set your desired Device Requirement
  19. Remove /base from resources and root dir paths. Also comment out ProGuard obfuscator.
  20. For testing purpose, write code to connect to http://www.google.com/ and then print the google’s home page’s html on the debugger console.
    p16
    p16-2
    Click here to download TestMidlet.java
  21. Run the BlackBerry MDS Simulator, a console window will open, minimize it and do not close it during development and testing.
  22. Run the JDWP module i.e. the BlackBerry debugger
  23. Now, from the Projects tab in the NetBeans IDE, right click on the TestProject node and select Debug Project.
  24. You will notice activities in the debug window and then debug console. Finally, the BlackBerry emulator will start; it will then try to connect to the debugger and then display the blackberry menu.
  25. Click on the console icon named “Blank” and then watch the JDWP’s debugger console, which shows all activities and console logs. You will notice that Google’s home page’s html is printed on the console.
  26. Finish.