Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

BlackBerry Java Application Development Using Visual Studio

0.00/5 (No votes)
22 Feb 2009 1  
BlackBerry Java application development using Visual Studio.

Introduction

BlackBerry JDE or any other platform like NetBeans could be used for BlackBerry Java application development. As a .NET developer, I prefer using Visual Studio because of the features it provides over the BlackBerry JDE, and I will try to explain the same in this article.

Background

I have been using the BlackBerry JDE for a while now since I started BlackBerry development. After becoming familiarized with the 4.2.1 API that I am using, I decided to use Visual Studio because of its capabilities and find it very handy. I still use the BlackBerry JDE for debugging and signing purposes, when required.

Details

Here are the cons and pros before you decide if you want to use Visual Studio:

Cons

  • Debugging
  • Signing
  • RIM BlackBerry API intellisense
  • Error navigation (Cannot navigate to the error line from the output window but could navigate to the file)

Pros (over RIM JDE)

  • Better syntax highlighting, code outlining (CTRL + M, O - collapses everything)
  • Intellisense
  • Code snippets (code snippet name - if, for, and tab + tab)
  • Commenting and uncommenting (CTRL + K, C)
  • Better formatting (CTRL + K, D), better navigation (for functions and classes using the top dropdowns), line numbers - easier to read.
  • Source gear vault integration
  • Better search, replace, and bookmarking capabilities (CTRL + K, K to bookmark, CTRL + K, N to move next etc.)
  • Get to use my customized Dark theme (the best of it)
  • And all other features VS2005 provides

I use VS2005 as J# support is removed in VS2008. Let's consider a Hello World project. You could see this line in the output window when you build the project in the BlackBerry JDE.

C:\Program Files\Research In Motion\BlackBerry JDE 4.2.1\bin\rapc.exe 
  -quiet import="..\..\Program Files\Research In Motion\BlackBerry JDE 
  4.2.1\lib\net_rim_api.jar" codename=com_rim_helloworld com_rim_helloworld.rapc 
  warnkey=0x52424200;0x52435200;0x52525400 C:\BBProjects\helloworld\HelloWorld.java 
  C:\BBProjects\helloworld\img\helloworld_jde.png 
  C:\BBProjects\helloworld\resource\HelloWorldRes.rrc 
  C:\BBProjects\helloworld\resource\HelloWorldRes.rrh 
  C:\BBProjects\helloworld\resource\HelloWorldRes_de.rrc 
  C:\BBProjects\helloworld\resource\HelloWorldRes_en.rrc 
  C:\BBProjects\helloworld\resource\HelloWorldRes_es.rrc 
  C:\BBProjects\helloworld\resource\HelloWorldRes_fr.rrc 
  C:\BBProjects\helloworld\resource\HelloWorldRes_it.rrc

If your project contains too many files, then the above line would be something like this:

C:\Program Files\Research In Motion\BlackBerry JDE 4.2.1\bin\rapc.exe 
  -quiet import="..\..\Program Files\Research In Motion\
                 BlackBerry JDE 4.2.1\lib\net_rim_api.jar" 
  codename=com_rim_helloworld com_rim_helloworld.rapc 
  warnkey=0x52424200;0x52435200;0x52525400 @com_rim_helloworld_build.files

@com_rim_helloworld_build.files contains all the files included in your project. RIM JDE will automatically create this for you when required.

This is important to build in Visual Studio to check if there are any errors in code. Now, let's open Visual Studio and create a new J# class library project (C# or J# project does not matter, as the file extension is what that matters):

Create the J# project in a different directory, delete the default class1 file, close VS, and move the J# project contents to your existing BlackBerry project so that everything is in one place. Now, open the project in VS and include the necessary files. This will look something like this at this point:

Now that you have included the files, you can code in Visual Studio and would require to build the project to check for the errors. Let's create a batch file to build the Java project from within the Visual Studio. Here is the code for building and showing if succeeded or not:

"C:\Program Files\Research In Motion\BlackBerry JDE 4.2.1\bin\rapc.exe" 
  -quiet import="..\..\Program Files\Research In Motion\
                 BlackBerry JDE 4.2.1\lib\net_rim_api.jar" 
  codename=com_rim_helloworld com_rim_helloworld.rapc 
  warnkey=0x52424200;0x52435200;0x52525400 
  C:\BBProjects\helloworld\HelloWorld.java 
  C:\BBProjects\helloworld\img\helloworld_jde.png 
  C:\BBProjects\helloworld\resource\HelloWorldRes.rrc 
  C:\BBProjects\helloworld\resource\HelloWorldRes.rrh 
  C:\BBProjects\helloworld\resource\HelloWorldRes_de.rrc 
  C:\BBProjects\helloworld\resource\HelloWorldRes_en.rrc 
  C:\BBProjects\helloworld\resource\HelloWorldRes_es.rrc 
  C:\BBProjects\helloworld\resource\HelloWorldRes_fr.rrc 
  C:\BBProjects\helloworld\resource\HelloWorldRes_it.rrc
  
@echo off
if not exist "com_rim_helloworld.err" goto 20
@ECHO "Build Failed."
goto end
:20
@ECHO "Build Succeeded."
del com_rim_helloworld.cod
:end

Create a batch file using the above code in the project directory and add this into External Tools to run within VS. You could do the same using the menu bar: Tools-->External Tools. Add one and setup the batch file, initial directory etc., as shown below:

You could set a keyboard shortcut like SHIFT + CTRL + F7 and execute it, and you will see the results in output window:

Just change something in the code and build again (using the shortcut or an external tool), and you will see the error details. You could then navigate to the appropriate file from clicking in the output window:

That's it, you are all set up for BlackBerry Java application development in Visual Studio. I use both Visual Studio (for development) and BlackBerry JDE (for debugging and signing) to get the best of both worlds. I have included the J# project with all the files in it.

Also, the BlackBerry build and signing process could be automated using BB Ant Tools, if required.

Hope you find this article useful, happy coding and have fun!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here