Vous êtes sur la page 1sur 5

HOWTO integrate the Blackberry IDE into eclipse

and known problems and issues

First: If you want to write a Blackberry application you don't need the EclipseME
plug-in. With EclipseME you're writing MIDlets, which are portable to all devices on
which a Java ME is running. A Java MIDlet application therefore produces a .jad file,
which describes the content of the executable .jar file.
As I noticed, when writing my standard HelloWorld application in the Blackberry
IDE (which is very uncomfortable and the reason why so many people try hard to
integrate the Blackberry stuff into eclipse), instead of the .jad file there appears a .cod
file in the
\Research In Motion\BlackBerry JDE 4.2.1\simulator directory.
This implies that you can run any MIDlet (.jad) on a Blackberry but a Blackberry
application (.cod) is Blackberry specific and not portable to other mobile devices.
The reasons for this are the special Blackberry APIs.

So, what I am describing is a way to setup eclipse to enable you to write Blackberry
applications. If you want to write a standard portable MIDlet, simply use EclipseME.

After searching and trying a couple of hours, I finally found http://a-developers-


notes.blogspot.com/2007/04/eclipse-environment-setup-for.html. Thanks a lot Alex!
I'm reusing your fabulous tutorial as follows.

Here we go:

1. Download and install Eclipse


2. Download and install Blackberry JDE
3. Download and install Apache ant (see Notes 3)
4. Download RAPC ant task jar file from
http://www.etaras.com/blackberry/rapc

Now let's setup our eclipse environment. These instructions are basically the same as
in the Blackberry IDE Developer Guide, Appendix: The Eclipse development environ-
ment

1. Start your Eclipse, switch to a brand-new workspace, for example


C:\RIM\workspace. (You also can use one of your existing workspaces, this will
cause no problems.)
2. Go to Window  Preferences  Java  Installed JREs, click on "Add" button.
3. In the dialog, leave the default "Standard VM" option for JRE type;
4. Type in a "JRE name" as you like, such as 'RIM JRE';
5. In "JRE Home Directory", navigate to your installed JDK home, such as
'C\Program Files\Java\jdk1.6.0';
6. Leave "Default VM Arguments" blank;
7. Now select all the jar files in "JRE System Libraries", then click "Remove" button
to remove all of them; Click "Add External JARs", navigate to you Blackberry JDE
installation folder, select lib/net_rim_api.jar, such as
'C:\Program Files\Research In Motion\BlackBerry JDE 4.2.1\lib\net_rim_api.jar'.
8. Click "OK" button to add the new JRE.
9. Check the checkbox of your newly added JRE to make it the default (Optional:
select this JRE, click on "Edit" button to see if the system libraries are still like you
set. It happened to me a couple times that eclipse added the jars in JRE home back
into the list.)

With the eclipse setup, we are ready to create our first project:

1. Go to File  New  Project, select "Java Project", enter Project Name "Hel-
loWorld", Make sure in the JRE group the "RIM JRE" is selected. In the "Project
Layout" group, I prefer to have src and class output into separate folders. Click
"Finish" button.
2. Right click the project, select New  Folder, create a folder named "lib"
3. Right click the project, select New  Folder, create a folder named "resources"
4. Right click "lib" folder, select "import"; in the dialog, select "general"  "file sys-
tem", import the anttask-rapc-1.8.jar you downloaded. Right click the jar file and
select "Build Path" --> "Add to Build Path".
5. Follow the same step to import an icon file in GIF format into "resources" folder
(.png works to). But don't add it to the classpath :-)
6. Create a package named "com.mycompany.sample"
7. Create a class named "HelloWorld.java" in this package and paste these code:

Pay special attention to the points, which are written in red. This values will change
depending on your system configuration and your naming.

package com.mycompany.sample;

import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;

public final class HelloWorld extends UiApplication {

public HelloWorld(){
super();
MainScreen screen = new MainScreen();
screen.add(new LabelField("Hello world!"));
pushScreen(screen);
}
public static void main(String[] args) {
new HelloWorld().enterEventDispatcher();
}
}
8. Now right click on the project name and create a new file named "build.xml", copy
and paste the following code and edit the JRE and RIM JDK pathes accordingly,
also search and replace the simulator batch file "8800.bat" to one that exists in your
JDE (this ant build script is modified based on a post in Blackberry Java Forum.)

<?xml version="1.0" encoding="UTF-8"?>

<project name="HelloWorld" default="buildRIM" basedir=".">

<taskdef name="rim" classname="com.etaras.anttask.rapc.RAPC" class-


path="lib/anttask-rapc-1.8.jar" />

<property name="jdehome" value="C:\Program Files\Research In Motion\BlackBerry


JDE 4.2.1" />
<property name="javahome" value="C:\Program Files\Java\jdk1.5.0_11"></property>
<property name="simulator" value="${jdehome}\simulator" />
<property name="bin" value="${jdehome}\bin" />

<target name="debug" depends="buildRIM">


<copy todir="${simulator}" overwrite="true">
<fileset dir=".">
<include name="*.cod" />
<include name="*.debug" />
<include name="*.csl" />
<include name="*.cso" />
</fileset>
</copy>
<exec executable="cmd.exe" dir="${bin}" spawn="true">
<arg value="/c" />
<arg value="jdwp.bat" />
</exec>
</target>

<target name="simulate" depends="deploy">


<exec executable="cmd.exe" dir="${simulator}" spawn="true">
<arg value="/c" />
<arg value="8800.bat" />
</exec>
</target>

<target name="deploy" depends="buildRIM">


<copy todir="${simulator}" overwrite="true">
<fileset dir=".">
<include name="*.cod" />
<include name="*.debug" />
<include name="*.csl" />
<include name="*.cso" />
</fileset>
</copy>
</target>

<target name="buildRIM" description="Composes RIM">


<rim jdehome="${jdehome}" javahome="${javahome}">
<workspace src="helloworld.jdw" build="true" update="true">
<cldc src="helloworld.jdp"
title="HelloWorld"
vendor="my company"
version="0.1"
description="HelloWorld"
arguments=""
systemmodule="false"
runonstartup="false"
startuptier="7"
ribbonposition="0"
output="helloworld"
options="-quiet"
update="true">
<files dir=".">
<include name="**/*.java" />
<include name="resources/**/*.*" />
</files>
<icons dir=".">
<include name="resources/**/*.png" />
<include name="resources/**/*.gif" />
</icons>
</cldc>
</workspace>
</rim>
</target>

</project>

9. Open a DOS window (cmd), change to the directory where you have your
build.xml file, type "ant simulate", this task will build the project, deploy it and
start the simulator.
This will only work, if your PATH-Variables in your system environment are set
correctly. See the Apache ant introduction for this issue.
Look for the logo you picked for your HelloWorld app and open it, you should see
a blank screen displaying "Hello World!". How exciting! (If you get an error mes-
sage, that Port 8000 is already in use see Note 4, at the end of this document.)

Until this point you have not needed to start the JDWP, which will allow you to con-
nect to the Blackberry Debugger from third party IDEs like Eclipse. Due to the fact,
that debugging an application without output sucks, the Blackberry IDE comes with
a debugger.
HOWTO Debug you application from within eclipse

1. Start the Blackberry debugger with Start  Programs  Research in Motion 


Blackberry IDE 4.2.1  JDWP. It is listening to the port 8000 by default.
2. Make sure the “Launch Simulator when debugger connects” field is active.
3. Switch to Eclipse. Window  Preferences  Java  Debug. In the “Communica-
tion” area set the values of “Debugger Timeout” and “Launch Timeout” to a
higher value. At least 10 times longer, if you can still not connect to the simulator
because of a Timeout, set the values still higher. Click OK and leave preferences.
4. Click on your project. Then Run  Open Debug Dialog  Java Remote Applica-
tion. Right click on it  New. Now you should have an entry with the name of
your project.
5. Click debug.
6. You can now normally set breakpoints as usual and debug step by step. You can
also use the System.out.println(“”); method for debugging. The output is dis-
played in the Remote Debug Server (which was started by JDWP). Click the out-
put tab and here your see your System.out.println()’s among other debugging
messages from the Blackberry VM.

Notes:
1. This will not run which Blackberry IDEs version lower then 4.1, because you will
need the JDWP to connect from third party IDEs to the Blackberry simulator for
debugging purpose.
2. The Java Compliance Level for the Blackberry project in Eclipse has to be 1.4 or
lower. Otherwise you will get some unexplainable error messages.
3. You really have to install Apache ant. It is not enough to use ant coming with
Eclipse, at least not if you are using the build.xml file delivered in this document.
As you can see: <exec executable="cmd.exe" dir="${simulator}" spawn="true"> de-
mands a start from the command line.
4. The reason why your port 8000 is in use, could be, that you have already started the
JDWP. Which you don’t need until this point. So close it. If you still get this message,
open the task manager and kill the application manually.

Vous aimerez peut-être aussi