Sunday 10 April 2011

Blackberry Development Using NetBeans

Requirements

Before you begin, you need to install the following software on your computer:
  • NetBeans 6.1
  • RIM BlackBerry Java Development Environment (JDE) v4.5

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.5.0).
  5. You can enter whatever you want for the Platform Name.
  6. Set Device Name to one of the supported devices: 8300, 8800
  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.
  1. 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.5.0\lib\net_rim_api.jar and click Open.
    Then click Next.
  2. 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.5.0\docs\api\. The Java Platform Manager should look like the following graphic:










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 MobileApplication1.
    If you do not want a sample MIDlet created for your project, uncheck the "Create Hello MIDlet" check box.




  1. Click Finish to create the Project.




  1. Select the Files Tab in the Explorer window and open the project's build.xml file. Add this fragment of code right before the </project> tag at the bottom of the file:

    <target name="pre-jar">
        <available file="${platform.home}/bin/rapc.exe" property="do.rapc"/>
        <condition property="jpda.port" value="8000">
            <isset property="do.rapc"/>
        </condition>
    </target>
    <target name="post-jar" if="do.rapc">
        <exec dir="${platform.home}/simulator" executable="${platform.home}/bin/rapc.exe" failonerror="true">
            <arg value="import=${platform.bootclasspath}"/>
            <arg value="codename=${name}"/>
            <arg value="-midlet"/>
            <arg value="jad=${basedir}/${dist.dir}/${dist.jad}"/>
            <arg value="${basedir}/${dist.dir}/${dist.jar}"/>
        </exec>
    </target>
    <target name="post-clean">
        <delete failonerror="false">
            <fileset dir="${platform.home}/simulator">
                <include name="**/${name}.*"/>
            </fileset>
        </delete>
    </target>




  1. Next you need to create an .alx file which is a Blackberry 'Application Loader' xml file, in the 'Files' pane, right-click and select 'new' > 'empty file'
    Name the file the same as your application (eg. myApp.alx), and add this xml data [important - only use numerics in the version number, any letters can cause issues for OTA installing of the application when you're done, for example do not use any 'beta' version notifiers like b1.0

 <loader version="1.0">

  <application id="BlackBerry">

               <name>

                  Black Berry

               </name>

               <description>

               </description>

               <version>

                     1.0

               </version>

               <vendor>

                    Mohammad Abu Hmead

               <vendor>

                <copyright>

                     Copyright © Mohammad Abu Hmead 2011

                </copyright>

                <fileset Java=1.25>

                    <directory></directory>

                    <files>

                       BlackBerry.cod

                    <files>

                </fileset>

   </application>

</loader>

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.5 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.
In your project, you still have the freedom to use various platforms for different project configurations. You can work around the limitation of one device per one custom platform by repeating the steps in Adding RIM as a Custom Emulator with an alternative platform name.

Reference:
http://jonathanhfisher.co.uk/newsitems/blackberrynetbeansdev/index.htm
http://www.netbeans.org/kb/55/blackberry.html

Java Platform Manager dialog with commands edited

1 comment:

  1. My cousin recommended this blog and she was totally right keep up the fantastic work!

    Blackberry Development

    ReplyDelete