Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
Posts: 8
Registered: ‎01-01-2009
My Device: Not Specified

How to use bb-ant-tools with Eclipse (without the Eclipse plugin)

A few years ago I posted (in the former BlackBerry Java Developers forum) steps for getting the HelloWorld demo to compile and debug in Eclipse using "etaras anttask." Since etaras no longer exists, and I haven't (yet) become happy with the Eclipse Plugin, I have rewritten those steps for using the bb-ant-tools and updated and tested the steps for compatibility with Eclipse 3.4.1 and BlackBerry JDE 4.3.0. You should also be able to use newer JDE's as well.


Prerequisites

1. You have installed Eclipse 3.4.1 or later.
2. You have installed the BlackBerry JDE 4.3.0. Find it at http://na.blackberry.com/eng/developers/javaappdev/devtools.jsp
3. You have installed Sun's JDK 5.0. Find it at http://java.sun.com/j2se/1.5.0/download.jsp

Extend the Sun JRE

1. Start Eclipse.
2. In the menubar, click Window > Preferences.
3. Select Java > Installed JREs.
4. Click Add.

5. Select Standard VM.

6. JRE home = the location of your Sun JRE. For example: C:\Java\jdk1.5.0_11\jre
JRE name = jre_1.5.0+rim4.3.0 (or whatever you like)
7. Click Add External JARs.
8. Browse to the lib folder of you installation of the BlackBerry JDE. For example: C:\Program Files\Research In Motion\BlackBerry JDE 4.3.0\lib
9. Select net_rim_api.jar.
10. Click Open.

Add the RIM API documentation

1. Still in the Add JRE window, expand the net_rim_api.jar file.
2. Select Javadoc location.
3. Click Javadoc Location... button.
4. Click Browse.
5. Navigate to the docs\api folder of your BlackBerry JDE installation. For example: C:\Program Files\Research In Motion\BlackBerry JDE 4.3.0\docs\api
6. Click OK. Click Finish. Click OK.

Create a new Helloworld Java Project

1. On the taskbar, click File > New > Project.
2. Select Java Project and click Next.
3. Project name = Helloworld

JRE = Use the specific JRE that you created above.

4. Click Finish.

Add the bb-ant-tools jar to the project


1. Download the bb-ant-tools.jar from http://bb-ant-tools.sourceforge.net.

2. In Eclipse's Package Explorer, right-click to highlight the Helloworld project folder.
3. Click New > Folder.
4. Folder name = lib.
5. Click Finish.
6. Copy bb-ant-tools.jar into Eclipse in the new lib folder.
7. Expand the lib folder and right-click bb-ant-tools.jar.
8. Click Build Path > Add to Build Path.

Copy Helloworld into the project

1. In Eclipse's Package Explorer, expand the Helloworld project folder.

2. There should already be a src folder. If not, right-click the project folder, select New > Source Folder, name it src, click Finish.

3. Create an output folder. Right-click the project folder, select New > Folder, name it output, click Finish.
4. Right-click on the src folder.
5. Click New > Package.
6. Name = com.rim.samples.device.helloworld
7. Click OK.
8. From the Windows desktop, open a Windows Explorer and navigate to the BlackBerry JDE's helloworld project. For example: C:\Program Files\Research In Motion\BlackBerry JDE 4.3.0\samples\com\rim\samples\device\helloworld
9. Copy the HelloWorld.java file from Windows Explorer into Eclipse under the Helloworld project's com.rim.samples.device.helloworld package. HelloWorld.java will indicate a compile error because the HelloWorldResResource interface is generated on-the-fly by the BlackBerry RAPC compiler.
10. In Eclipse's Package Explorer, right-click on the Helloworld project folder.
9. click New > Folder.
11. Folder name = resource.
12. Click Finish.
13. Copy the files from the BlackBerry JDE's helloworld project img folder into the new resource folder in Eclipse.

14. Copy all seven or so files with names beginning HelloWorldRes from the resource folder in the Windows Explorer (at the same level as the helloworld folder) into the new resource folder in Eclipse.

Create the build.xml ant task

1. In Eclipse's Package Explorer, right-click the Helloworld project folder.
2. Click New > File.
3. File name = build.xml.
4. Click Finish.
5. Put the XML at the end of this file as the content of the build.xml. Be sure to modify any file paths appropriately. Modify the bat file referenced by the simulate task to refer to the device that you wish to simulate. For documentation on the elements of this ant task see http://bb-ant-tools.sourceforge.net.
6. Right-click build.xml.
7. Click Run As > Ant Build...
8. Under the Targets tab, check only buildRIM.
9. Click Run.
10. The message BUILD SUCCESSFUL should appear in Eclipse's console output.
11. Right-click the output folder in the Helloworld project and click Refresh. The generated BlackBerry JDE files should appear.

Simulate the Helloworld project

1. In Eclipse's Package Explorer, right-click build.xml.
2. Click Run As > Ant Build...
3. Under the Targets tab, check only simulate.
4. Click Run.

Note: The BlackBerry executable files are deployed under the BlackBerry JDE's simulator folder. For example: C:\Program Files\Research In Motion\BlackBerry JDE 4.3.0\simulator. You can run the clean.bat file in this folder to delete all of the files deployed since the JDK was installed.

Debug the Helloworld project

1. In Eclipse's Package Explorer, right-click build.xml.
2. Click Run As > Ant Build...
3. Under the Targets tab, check only debug.
4. Click Run.
5. The RIM Remote Debug Server will launch.
6. In Eclipse's Package Explorer, right-click the Helloworld project folder.
7. Click Debug As > Debug Configurations.
8. Highlight Remote Java Application.
9. Click New.
10. Click Debug.

Note: According to the BlackBerry Application Developer Guide if you see the message "Failed to connect to remove VM. Connection timed out", increase the Debugger Timeout in Eclipse under Windows > Preferences > Java > Debug > Communication.


build.xml content:

(Modify any file paths appropriately. Modify the bat file referenced by the simulate task to refer to the device that you wish to simulate. For documentation on the elements of this ant task see http://bb-ant-tools.sourceforge.net.)

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

<project name="${description}" default="buildRIM" basedir=".">

 <taskdef
  resource="bb-ant-defs.xml"
  classpath="lib/bb-ant-tools.jar" />

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

 <property name="simulator" value="${jdehome}\simulator" />

 <property name="bin" value="${jdehome}\bin" />

 <target name="debug" depends="deploy" description="Builds, Deploys Project and Launches Remote Debug Server">
  <exec executable="cmd.exe" dir="${bin}" spawn="true">
   <arg value="/c" />
   <arg value="jdwp.bat" />
  </exec>
 </target>

 <target name="simulate" depends="deploy" description="Builds, Deploys Project and Launches Simulator">
  <exec executable="cmd.exe" dir="${simulator}" spawn="true">
   <arg value="/c" />
   <arg value="8130.bat" />
  </exec>
 </target>
 
 <target name="deploy" depends="buildRIM" description="Builds and Deploys Project">
  <copy todir="${simulator}" overwrite="true">
   <fileset dir="output">
    <include name="*.cod" />
    <include name="*.debug" />
    <include name="*.csl" />
    <include name="*.cso" />
   </fileset>
  </copy>
 </target>

 <target name="buildRIM" description="Builds Project">
  <rapc jdehome="${jdehome}"
   jdkhome="C:\Program Files\Java\jdk1.5.0_11"
   destdir="output"
   output="HelloWorld"
   quiet="false">
   
   <jdp type="cldc"
    title="Hello World Demo"
    vendor="Vendor=Research In Motion Ltd."
    version="Version=0.9"
    description="HelloWorld Application"
    arguments=""
    systemmodule="false"
    runonstartup="false"
    startuptier="7"
    ribbonposition="0"
    icon="../resource/helloworld_jde.png">
   </jdp>
   
   <src>
    <fileset dir=".">
     <include name="src/**/*.java" />
     <include name="resource/**/*.*" />
    </fileset>
   </src>
  </rapc>
 </target>

</project>

 

New Developer
Posts: 12
Registered: ‎01-14-2009
My Device: Not Specified

Re: How to use bb-ant-tools with Eclipse (without the Eclipse plugin)

You...are...AWESOME.

 

The build.xml bit at the end was just what I needed.

 

I already have ant and antenna set up in my dev environment. I use EclipseME inside Eclipse for straight j2me and have a build.xml file that lives along side of it. So I use EclipseME for straight up dev work and the build.xml when I want to push out of bunch of production builds (also keeps me free from being tied to IDE if necessary).

 

I happy to say the same thing works with Blackberry Eclipse plug in. I can use the plug in to simply develop in the IDE and even use "Run as".

 

As I already have BB Eclipse plugin, I skipped all your steps except for the downloading of BB ant jar file. I then have downloaded the ant BB jar mentioned into the lib directory of ant.

 

With only minor tweaking to your build.xml file I was off and running for BB. Now I can merge that into my main build.xml for j2me have both from the same place. woo hoo!

 

Other than minor path stuff, the  one addition I made was an init target since as written the build.xml complained about the "output" directory missing.

 

here is the change I did if it helps anyone.

 

<target name="init">
        <delete dir="output"/>
        <mkdir dir="output"/>
    </target>

 

then added "depends=init" to buildRIM target.

New Developer
Posts: 10
Registered: ‎10-26-2008
My Device: Not Specified

Re: How to use bb-ant-tools with Eclipse (without the Eclipse plugin)

Thank you for taking the time to write that guide! Frustrated with the Eclipse plugin I turned to bb-tools but I was having some problems debugging from Eclipse. Your post has made everything clear.
Developer
Posts: 143
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to use bb-ant-tools with Eclipse (without the Eclipse plugin)

I have a wiki on how to do this too at http://wiki.berrysoft.net, where you can find step-by-step on how I've setup things.

 

New Developer
Posts: 18
Registered: ‎11-20-2008
My Device: Not Specified

Re: How to use bb-ant-tools with Eclipse (without the Eclipse plugin)

Awesome! just what I needed. Thanks a lot.

 

BTW, when I try to run the debug target, I get a message box with a message "Cannot open port 8000. Please try another port". If I execute jdwp.bat file manually I get the same result. Does anyone know how to change port?

Developer
Posts: 48
Registered: ‎02-10-2009
My Device: Not Specified

Re: How to use bb-ant-tools with Eclipse (without the Eclipse plugin)

Thanks for this! With very little tweaking I was able to get bb-ant-tools working in my environment. This will help me greatly in getting other developers to build and deploy BlackBerry applications.
Developer
Posts: 53
Registered: ‎12-11-2008
My Device: Not Specified

Re: How to use bb-ant-tools with Eclipse (without the Eclipse plugin)

Hi all, I faced with the following issue building BB project with ANT

When project has some resources (suppose in "res" folder) after compilation if we look into generated jar file, all resources will be placed under root folder - along with *.cod files, not under "res" folder

 

But if we build project using JDE (rapc.exe instead of rapc.jar) all resources will be placed under "res" folder.

 

Can somebody point me how to make ANT rapc task copy resources in res folder, but not in root folder.

New Developer
Posts: 69
Registered: ‎06-10-2009
My Device: Not Specified

Re: How to use bb-ant-tools with Eclipse (without the Eclipse plugin)

[ Edited ]

How can I include a directory with images on the build.xml?

My program is not finding the images on runtime.

 

Thanks in advance.

 

Message Edited by avandelay on 08-25-2009 11:29 AM
New Developer
Posts: 69
Registered: ‎06-10-2009
My Device: Not Specified

Re: How to use bb-ant-tools with Eclipse (without the Eclipse plugin)

Currently the images are being included on the cod, but it seems to be a path problem. The build.xml is like this:

 

 

<src> <fileset dir="..."> <include name="**/*.java" /> <include name="images/*.png" /> <include name="images/*.gif" /> <include name="images/*.jpg" /> </fileset> </src>

 

Any ideas?

 

New Developer
Posts: 12
Registered: ‎01-14-2009
My Device: Not Specified

Re: How to use bb-ant-tools with Eclipse (without the Eclipse plugin)

Just a guess, but what if you had two file set tags? I notice the dir is set to default to top level.

 

Try one with src set to top and another with images set to "res"?