Sun Java System Mobile Enterprise Platform 1.0 Developer's Guide for Client Applications

ProcedureTo Import the SecureMusicDB Sources into NetBeans IDE as a BlackBerry Project

To build and run a SecureMusicDB project for the BlackBerry from sources in NetBeans IDE, follow these steps.

  1. To obtain the MEP client library bundle, go to the following URL: http://www.sun.com/software/products/mep/get.jsp.

  2. Click Download, provide the requested information, then click Log In and Continue.

  3. Download the sjsmep-client-1_0_02-fcs.zip bundle.

  4. Unzip the bundle in a location of your choosing (for example, under C:\).

  5. Start NetBeans IDE.

    The first time you start NetBeans IDE, you are prompted to install some updates. Install them.

  6. In NetBeans IDE, follow these steps to create a Mobility Project and import the secure-musicdb sources.

    1. From the File menu, select New Project.

      The Choose Project screen appears.

    2. Click Mobility, then click Mobile Project from Existing MIDP Sources.

    3. Click Next.

      The Specify MIDP Sources Screen appears.

    4. In the Sources Location field, specify the location of the secure-musicdb sources in the unzipped bundle. For example, if you unzipped the bundle to the C:\ directory, specify the following:

      C:\sjsmep-client-1_0_02-fcs\samples\mcbo\secure-musicdb\src
    5. Click Next.

      The Name and Location Screen appears.

    6. Type a name for the Project or keep the default name.

    7. Click Next.

      The Default Platform Selection Screen appears.

    8. Set the Emulator Platform to “BlackBerry JDE 421” and verify that the Device is 8800.

    9. Click Finish.

      The project appears in the Projects pane.

  7. To add the file mep_client_api.jar to the supported Libraries & Resources, follow these steps.

    1. Right-click the project and select Properties.

    2. Click Libraries & Resources.

    3. Click Add Jar/Zip.

    4. Browse to the location of the unzipped bundle above the lib directory to add mep_client_api.jar.

      For example, if you unzipped the bundle to the C:\ directory, the file name would be C:\sjsmep-client-1_0_02-fcs\lib\BlackBerry\mep_client_api.jar.

    5. Click OK.

    6. Click the Files tab (next to the Projects tab) and open the project.properties file under the nbproject directory.

    7. Edit the file.reference.mep_client_api.jar property to contain the fully qualified path name of the mep_client_api.jar file.

      For a BlackBerry project, the pathname must be absolute, not relative.

      For example, if you unzipped the bundle to the C:\ directory, edit the property definition to look like this:

      file.reference.mep_client_api.jar=C:/sjsmep-client-1_0_02-fcs/lib/BlackBerry/mep_client_api.jar

      Use forward slashes (/) instead of the usual Windows file separator.

  8. Click the Files tab and open the project's build.xml file.

  9. Add the following code fragment immediately before the </project> tag at the end of the file:

        <target name="do-preprocess">
            <fail unless="libs.ant-contrib.classpath">
         Classpath to Ant Contrib library (libs.ant-contrib.classpath property) is not set.
            </fail>
            <taskdef resource="net/sf/antcontrib/antlib.xml">
                <classpath>
                    <pathelement path="${libs.ant-contrib.classpath}"/>
                </classpath>
            </taskdef>
            <available file="${platform.home}/bin/rapc.exe" property="do.rapc"/>
            <if>
                <isset property="do.rapc"/>
                <then>
                    <property name="jpda.port" value="8000"/>
                    <path id="antlib.classpath">
                        <fileset dir="${user.dir}/mobility8/modules/ext/" 
                                 includes="ant-contrib-1.0b3.jar"/>
                    </path>
                    <mkdir dir="${dist.dir}"/>
                    <path id="src-files">
                        <fileset dir="${src.dir}" includes="**/*.*"/>
                    </path>
                    <property name="srcs" value="${toString:src-files}"/>
                    <for list="${srcs}" param="file" delimiter=";" trim="true">
                        <sequential>
                            <echo message="@{file}${line.separator}" 
                                  file="${src.dir}/${name}_build.files" append="true"/>
                        </sequential>
                    </for>
                    <touch file="${dist.dir}/${dist.jar}"/>
                    <nb-overrideproperty name="buildsystem.baton" 
                                         value="${preprocessed.dir}"/>
                </then>
                <else>
                    <nb-overrideproperty name="buildsystem.baton" value="${src.dir}"/>
                    <antcall target="${name}-impl.do-preprocess"/>
                </else>
            </if>
        </target>
        <target name="do-compile">
            <if>
                <isset property="do.rapc"/>
                <then>
                    <antcall target="create-jad"/>
                    <antcall target="update-jad"/>
                    <copy file="${dist.dir}/${dist.jad}" toDir="${src.dir}"/>
                    <exec dir="${src.dir}" 
                          executable="${platform.home}/bin/rapc.exe" failonerror="true">
                        <arg value="-quiet"/>
                        <arg value="import=${platform.bootclasspath};${libs.classpath}"/>
                        <arg value="codename=${name}"/>
                        <arg value="-midlet"/>
                        <arg value="jad=${dist.jad}"/>
                        <arg value="@${name}_build.files"/>
                    </exec>
                    <delete file="${basedir}/${src.dir}/${name}_build.files"/>
                    <copy file="${name}.alx" todir="${dist.dir}"/>
                    <nb-overrideproperty name="buildsystem.baton" 
                                         value="${build.classes.dir}"/>
                </then>
                <else>
                    <nb-overrideproperty name="buildsystem.baton" 
                                         value="${preprocessed.dir}"/>
                    <antcall target="${name}-impl.do-compile"/>
                </else>
            </if>
        </target>
        <target name="pre-obfuscate">
            <nb-overrideproperty name="buildsystem.baton" value="${build.classes.dir}"/>
        </target>
        <target name="post-jar" if="do.rapc">
            <move todir="${dist.dir}">
                <fileset dir="${src.dir}">
                    <include name="**/${name}*.*"/>
                </fileset>
            </move>
            <copy todir="${platform.home}/simulator" verbose="true">
                <fileset dir="${dist.dir}">
                    <include name="**/${name}*.*"/>
                </fileset>
            </copy>
        </target>
        <target name="post-clean">
            <delete failonerror="false" includeemptydirs="true">
                <fileset dir="${platform.home}/simulator">
                    <include name="**/${name}*.*"/>
                </fileset>
                <fileset dir="${dist.dir}">
                    <include name="**/*.*"/>
                </fileset>
                <fileset dir="${src.dir}">
                    <include name="**/${name}*.*"/>
                </fileset>
            </delete>
        </target>
  10. Create an .alx file for this project.

    1. Click the Files tab.

    2. Right-click your project and select New->Other.

    3. In the Choose File Type screen, click Other, then click Empty File.

    4. Click Next.

    5. In the Name and Location screen, give the file the same name as your project, with the extension .alx.

      For example, if bb-secure-musicdb is the project name, name the file bb-secure-musicdb.alx.

    6. Click Finish.

      The empty file opens.

    7. Copy and paste the following text into the file, replacing myProject with your project name, and including any vendor and copyright information needed for your application.

      <loader version="1.0">
          <application id="myProject">
              <name>
                  myProject
              </name>
              <description/>
              <version>
                  1.0
              </version>
              <vendor>
              </vendor>
              <copyright>
              </copyright>
              <fileset Java="1.3">
                  <directory/>
                  <files>
                      myProject.cod
                  </files>
              </fileset>
              <application id="mep_client_api">
                  <name/>
                  <description/>
                  <version>
                      1.0
                  </version>
                  <vendor>
                      Sun Microsystems Inc.
                  </vendor>
                  <copyright>
                      Copyright (c) 2008 Sun Microsystems Inc.
                  </copyright>
                  <fileset Java="1.3">
                      <directory/>
                      <files>
                          mep_client_api.cod
                      </files>
                  </fileset>
              </application>
          </application>
      </loader>
    8. Save and close the file.

  11. Copy the file mep_client_api.cod from the directory C:\sjsmep-client-1_0_02-fcs\lib\BlackBerry to the simulator directory of the BlackBerry JDE (for example, C:\Program Files\Research In Motion\BlackBerry JDE 4.2.1\simulator).

  12. Click the Projects tab, then right-click your secure-musicdb project and select Clean & Build.

  13. Right-click your secure-musicdb project and select Run.

    The BlackBerry Device Simulator appears.


    Note –

    When you select Run, NetBeans IDE automatically loads the application on the Simulator using the .jad and .jar files (not the .cod file). To load the application from the .cod file created, use the Load Java Program option in the Simulator.


  14. Launch the MepSecureJdbcMIDlet application and perform a Sync.


    Note –

    The MDS must be running for the client to perform syncs. If you started the JDE, MDS should get launched automatically. Otherwise, start MDS manually as follows: From the Windows Start menu, choose All Programs->Research in Motion->BlackBerry Email and MDS Services Simulators 4.1.4->MDS.


Next Steps

To remove the application from the Simulator, delete the .jad, .jar, and .cod files from the Simulator directory within the JDE and execute the three erase options in the JDE under File->Erase Simulator File.