Thursday, July 24, 2008

Developing mobile applications using Gear episode 1: Create the first empty application

This is the first episode of a series of tutorials about developing mobile applications in J2ME using Gear framework. This tutorial will cover the first steps required to start developing any J2ME applications with or without using the Gear framework, the next tutorials will be more focused on Gear based applications. Every step of the tutorial has been tested on Windows Vista/XP and Ubuntu Linux, if you want to develop using MacOS, due to the lack of official Sun emulator, you should try MPowerPlayer or MicroEmulator tutorials.

Step 1: Obtain the required software
There are two IDEs suitable for J2ME development: Eclipse and NetBeans, this tutorial will cover the steps required to develop using Eclipse. The required software thus will be:
Download Eclipse IDE and Sun WTK from the links above and install both on your system. Installing Eclipse requires simply to extract the compressed package downloaded from the Eclipse site in a folder, typically "c:\Programs" on Windows or "/opt" on Linux. The Wireless Toolkit has a self installing procedure that will ask the user the target installation directory, again the typical directories are "c:\Programs" and "/opt".
If you plan to use Gear framework download the Gear jar and javadoc and put them in a directory of your choice (/opt in this tutorial).
We'll assume that after this step you'll have an Eclipse and a WTK directory in either one of the two directories listed above and eventually Gear files in the directory "/opt".


Step 2: Configure Eclipse and EclipseME
Now that you have installed the basic software it is time to execute Eclipse and configure it to support J2ME development.

  • First run Eclips and go to the plug in install section.
  • Select "Search for new features to install", click "Next" and add a new remote site.
  • Select finish and install the plugin.
  • Go to the preferences dialog and enter the "J2ME" section.
  • Enter the "Device Management" subsection, press the "Import" button, select the directory where you have installed the WTK before and press "Finish" button.
  • Now go to the "Java->Debug" section of the preferences and change the "Debugger timeout" value to 30000.
Now Eclipse is configured correctly to write, run and debug J2ME applications.

Step 3: Create an application and reference the Gear framework
Now it is time to create an empty J2ME application.
  • Enter the Eclipse "New" menu and select "Other".
  • Now create a new J2ME midlet suite, enter the name
    and press Next until you find the "Java settings" screen.
The following steps are optional, if you don't want to use the Gear framework just press "Finish".
  • Select the "Libraries" tab, press the "Add External JARs..." button and select the Gear jar file from the directory where you saved it.
  • Add JavaDoc to Gear: click "javadoc location" sub menu and press the "Edit" button.
  • Select Gear to be deployed within your application: enter the "Order and Export" tab, and click on Gear check box.
Now simply press the "Finish" button and you'll be ready to start programming your J2ME application.

Conclusions
The midlet suite we have created, is now ready to be filled with a set of midlets and all your application classes. In the next tutorials we'll describe how to create the midlets, how to display an interface, how to andle user's input and much more.