Sun GlassFish Mobility Platform 1.1 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 Sun GlassFish Mobility Platform 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 sgmp-client-1_1_01-fcs-b02.zip bundle.

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

  5. Unzip the source files for the SecureMusicDB project.

    1. Navigate to the directory C:\sgmp-client-1_1_01-fcs-b02\samples\secure-musicdb\src\mcbo.

    2. Extract the files from the securemusicdb-sources.jar file to the C:\sgmp-client-1_1_01-fcs-b02\samples\secure-musicdb\src\mcbo directory.

      You could use WinZip or the jar xvf command, for example, to extract the files.

    3. Remove the META-INF directory and its contents (the file MANIFEST.MF).

  6. Start NetBeans IDE.

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

  7. In NetBeans IDE, follow these steps to create a Java ME Project and import the secure-musicdb sources.

    1. From the File menu, select New Project.

      The Choose Project screen appears.

    2. Click Java ME, then click Mobile Project with 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 you extracted. For example, if you unzipped the bundle to the C:\ directory, specify the following:

      C:\sgmp-client-1_1_01-fcs-b02\samples\secure-musicdb\src\mcbo

      Leave the JAD/Manifest Location field empty.

    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.

  8. To specify the MIDlet and icon to be used, follow these steps.

    1. Right-click the project and select Properties.

    2. Click the Application Descriptor node.

    3. Click the MIDlets tab.

    4. If the SecureJdbcMIDlet appears, click Edit. If it does not, click Add.

      In the Add MIDlet dialog, the MIDlet name and class, SecureJdbcMIDlet and sample.SecureJdbcMIDlet, are already filled in.

    5. For the MIDlet Icon, select /Clear_Note_32.png from the menu (it is the only choice). If no menu appears, type the value in the field.

    6. Click OK, then click OK in the properties dialog.

  9. To add the files mep_client_api.jar and jerseyme_api.jar to the supported Libraries & Resources, follow these steps.

    1. Right-click the project and select Properties.

    2. Click Libraries & Resources under Build.

    3. Click Add Jar/Zip.

    4. Browse to the lib\BlackBerry directory to add mep_client_api.jar.

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

    5. From the same location, add jerseyme_api.jar.

    6. Click OK.

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

    8. 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:/sgmp-client-1_1_01-fcs-b02/lib/BlackBerry/mep_client_api.jar

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

    9. Edit the file.reference.jerseyme_api.jar property to contain the fully qualified path name of the jerseyme_api.jar file.

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

      file.reference.jerseyme_api.jar=C:/sgmp-client-1_1_01-fcs-b02/lib/BlackBerry/jerseyme_api.jar
    10. Edit the file.reference.src-mcbo property to contain the fully qualified path name of the project sources.

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

      file.reference.src-mcbo=C:/sgmp-client-1_1_01-fcs-b02/samples/secure-musicdb/src/mcbo
  10. Click the Files tab and open the project's build.xml file.

  11. 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>
  12. 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) 2009 Sun Microsystems Inc.
                  </copyright>
                  <fileset Java="1.3">
                      <directory/>
                      <files>
                          mep_client_api.cod
                      </files>
                      <files>
                          jerseyme_api.cod
                      </files>
                  </fileset>
              </application>
          </application>
      </loader>
    8. Save and close the file.

  13. Copy the files mep_client_api.cod and jerseyme_api.cod from the directory C:\sgmp-client-1_1_01-fcs-b02\lib\BlackBerry to the simulator directory of the BlackBerry JDE (for example, C:\Program Files\Research In Motion\BlackBerry JDE 4.2.1\simulator).

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

    If a message that begins error while reading original manifest appears, you can ignore it.

  15. 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). If you want to load the application from the .cod file created, use the File->Load Java Program option in the Simulator.


  16. Launch the SecureJdbcMIDlet application and perform a Sync.

    The icon for the application is a musical note.


    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.