Pages

Tuesday 10 May 2011

Blackberry with Lwuit using Netbeans IDE

Step 1:
Fetch the LWUIT sources from SVN and create the BlackBerryPort project.
Or Download Link Project
Step 2: Blackberrry Port Project creation:
RIM port needs to replace some classes from LWUIT for Blackberry device supporting. 1. Remove: com.sun.lwuit.animations.Transition3D.java file from the LWUIT MIDP source code and clean & build. This is important, because, Blackberry doesn't support M3G classes. Clean & Build the BlackberryPort (BlackberryPort is within the LWUIT source code, both LWUIT andBlackberryPort are netbeans projects).
Step 3:
If not interested to create blackberry port and edit lwuit source Project please follow the step to create Blackberry with Lwuit project,some changes we need, but correctly follow steps
1.Create J2ME Application project
2. Insert the below code in \build.xml
 <target name="create-cod" if="blackberry.trigger">
        <exec dir="${dist.dir}" executable="java" failonerror="true">
            <arg value="-cp"/>
            <arg value="${platform.home}/bin/rapc.jar"/>
            <arg value="net.rim.tools.compiler.Compiler"/>
            <arg value="import=${platform.bootclasspath}"/>
            <arg value="codename=${name}"/>
            <arg value="-cldc"/>
            <arg value="jad=${basedir}/${dist.dir}/${dist.jad}"/>
            <arg value="${basedir}/${dist.dir}/${dist.jar}"/>
        </exec>
        <property file="${dist.dir}/${dist.jad}"/>
        <echo file="${basedir}/${dist.dir}/${name}.alx">
&lt;loader version="1.0"&gt;
    &lt;application id="${name}"&gt;
        &lt;name&gt;
            ${MIDlet-Name}
        &lt;/name&gt;
        &lt;description&gt;
            ${MIDlet-Description}
        &lt;/description&gt;
        &lt;version&gt;
            ${MIDlet-Version}
        &lt;/version&gt;
        &lt;vendor&gt;
            ${MIDlet-Vendor}
        &lt;/vendor&gt;
        &lt;copyright&gt;
            ${MIDlet-Copyright}
        &lt;/copyright&gt;
        &lt;fileset Java="1.0"&gt;
            &lt;directory/&gt;
            &lt;files&gt;${name}.cod&lt;/files&gt;
        &lt;/fileset&gt;
    &lt;/application&gt;
&lt;/loader&gt;
        </echo>
    </target>
    <target name="install-on-nokia-device" depends="init">
        <!-- If you are using a different directory for the Nokia PC suite just update the DIR -->
        <echo>Installing ${basedir}\dist\${config.active}\${name}</echo>
        <exec dir="${dist.dir}" executable="c:\Program Files (x86)\Nokia\Nokia PC Suite 7\ApplicationInstaller.exe"
            failonerror="true">
            <arg value="${basedir}\dist\${config.active}\${name}.jar"/>
        </exec>
    </target>
    <target name="install-on-rim-device" if="blackberry.trigger" depends="init">
        <!-- Uncomment and replace ??? with your password to sign the app  before deployment to device -->
        <!-- exec dir="${dist.dir}" executable="java" failonerror="true">
            <arg value="-jar"/>
            <arg value="${platform.home}/bin/SignatureTool.jar"/>
            <arg value="-a"/>
            <arg value="-p"/>
            <arg value="???"/>
            <arg value="-c"/>
            <arg value="-r"/>
            <arg value="."/>
        </exec -->
        <exec dir="${dist.dir}" executable="${platform.home}/bin/JavaLoader.exe" failonerror="true">
            <arg value="-u"/>
            <arg value="load"/>
            <arg value="${basedir}\dist\${config.active}\${name}.cod"/>
        </exec>
    </target>
3: In /nbproject/project.properties, change
all.configurations=\
Before:
to
all.configurations=\ ,BlackBerry,BlackBerryTouch
After :
4: In/nbproject/project.properties, insert bellow code
Before Code:
configs.BlackBerry.abilities=MMAPI=1.1,SATSAJCRMI=1.0,SATSACRYPTO=1.0,JSR82=1.1,JSR226=1.0,MIDP=2.1,JSR229=1.1.0,RIM=,SATSAAPDU=1.0,CLDC=1.1,JSR177=1.0,JSR179=1.0.1,J2MEWS=1.0,WMA=2.0,JSR172=1.0,ColorScreen,OBEX=1.0,JSR238=1.0,JSR239=1.0,JSR211=1.0,JSR234=1.0,ScreenWidth=240,JSR75=1.0,SATSAPKI=1.0,JSR184=1.1,ScreenHeight=320,ScreenColorDepth=8,JSR180=1.0.1,J2MEXMLRPC=1.0
configs.BlackBerry.extra.classpath=${file.reference.NokiaIAP_API.jar}
configs.BlackBerry.javac.source=1.3
configs.BlackBerry.javac.target=1.3
configs.BlackBerry.libs.classpath=${file.reference.BlackberryPort.jar}
configs.BlackBerry.obfuscation.custom=
configs.BlackBerry.obfuscation.level=0
configs.BlackBerry.platform.active=BlackBerry_JDE_4_6_0
configs.BlackBerry.platform.active.description=BlackBerry JDE 4.6.0
configs.BlackBerry.platform.apis=JSR75-1.0
configs.BlackBerry.platform.bootclasspath=${platform.home}/lib/net_rim_api.jar
configs.BlackBerry.platform.configuration=CLDC-1.1
configs.BlackBerry.platform.device=9000
configs.BlackBerry.platform.fat.jar=true
configs.BlackBerry.platform.profile=MIDP-2.0
configs.BlackBerry.platform.trigger=CLDC
configs.BlackBerry.platform.type=CUSTOM
configs.BlackBerry.sign.alias=minimal
configs.BlackBerry.sign.enabled=false
configs.BlackBerry.sign.keystore=${file.reference.builtin.ks}
configs.BlackBerryTouch.abilities=MMAPI=1.1,SATSAJCRMI=1.0,SATSACRYPTO=1.0,JSR82=1.1,JSR226=1.0,MIDP=2.1,JSR229=1.1.0,RIM=,SATSAAPDU=1.0,CLDC=1.1,JSR177=1.0,JSR179=1.0.1,J2MEWS=1.0,WMA=2.0,JSR172=1.0,ColorScreen,OBEX=1.0,JSR238=1.0,JSR239=1.0,JSR211=1.0,JSR234=1.0,ScreenWidth=240,JSR75=1.0,SATSAPKI=1.0,JSR184=1.1,ScreenHeight=320,ScreenColorDepth=8,JSR180=1.0.1,J2MEXMLRPC=1.0
configs.BlackBerryTouch.extra.classpath=${file.reference.NokiaIAP_API.jar}
configs.BlackBerryTouch.javac.source=1.3
configs.BlackBerryTouch.javac.target=1.3
configs.BlackBerryTouch.libs.classpath=${file.reference.BlackberryPort_Touch.jar};${file.reference.LWUIT.jar};${file.reference.LWUIT4IO.jar};${file.reference.NokiaIAP_API.jar}
configs.BlackBerryTouch.platform.active=BlackBerry_JDE_4_7_0
configs.BlackBerryTouch.platform.active.description=BlackBerry JDE 4.7.0
configs.BlackBerryTouch.platform.apis=JSR179-1.0
configs.BlackBerryTouch.platform.bootclasspath=${platform.home}/lib/net_rim_api.jar
configs.BlackBerryTouch.platform.configuration=CLDC-1.1
configs.BlackBerryTouch.platform.device=9500
configs.BlackBerryTouch.platform.fat.jar=true
configs.BlackBerryTouch.platform.profile=MIDP-2.0
configs.BlackBerryTouch.platform.trigger=CLDC
configs.BlackBerryTouch.platform.type=CUSTOM
configs.BlackBerryTouch.sign.alias=untrusted
configs.BlackBerryTouch.sign.enabled=true
configs.BlackBerryTouch.sign.keystore=${file.reference.builtin.ks}
5: keystore Process In/nbproject/project.properties, findfile.reference.builtin.ks while not in a code insert below code
file.reference.builtin.ks=${netbeans.user}/config/j2me/builtin.ks
6: In/nbproject/project.properties, change
sign.keystore=
to
sign.keystore=${file.reference.builtin.ks}
After Code:
7.Then we right click the projectèResolve Solve Reference Problem
We need add Blackberry and LWUIT supported Jars below in link:
Step 3:
MainMIDlet.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import com.sun.lwuit.Command;
import com.sun.lwuit.Display;
import com.sun.lwuit.Form;
import com.sun.lwuit.Label;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.util.Resources;
import java.io.IOException;
/**
* @author Administrator
*/
public class MainMIDlet extends
//#ifdef RIM
net.rim.device.api.ui.UiApplication
//#else
//#javax.microedition.midlet.MIDlet
//#endif
{
public Resources res;
//#ifndef RIM
//#
//#endif
//#ifdef RIM
public static void main(String[] argv)
{
System.out.println("starting app...");
new MainMIDlet().startApp();
}
public void notifyDestroyed() {
System.exit(0);
}
public void platformRequest(String s) {
net.rim.blackberry.api.browser.Browser.getDefaultSession().displayPage(s);
}
//#endif
public void startApp() {
Display.init(this);
try {
res = com.sun.lwuit.util.Resources.open("/blue.res");
} catch (IOException ex) {
}
com.sun.lwuit.plaf.UIManager.getInstance().setThemeProps(res.getTheme(res.getThemeResourceNames()[0]));
Form f = new Form();
f.setTitle("Blackberry with LWUIT");
f.setLayout(new BorderLayout());
f.addComponent("Center",
new Label("Finally we got it"));
f.addCommand(new Command("Exit") {
public void actionPerformed(ActionEvent ae) {
notifyDestroyed();
}
});
f.show();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public static Resources getResource(String name) throws IOException {
return Resources.open("/" + name + ".res");
}
}
Sample BlackApp Project
Note:
While we can’t build Blackberry project or Simulator Problem Please install the Blackberry Ant Tools
Download BB AnT Tools, make sure you are using Ant 1.7 or higher.
This will provide support for tasks like:

  • rapc

  • sigtool

  • alx

  • jadtool
5.Unzip and copy the file "bb-ant-tools.jar" to the ${Netbeans-home}/java/ant/lib directory.
References
Try it...
To know more about the ANT build files, review the references.

No comments:

Post a Comment