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.
Here we go:
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
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 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.)
</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
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.