C H A P T E R  3

Advanced Issues

This chapter describes several advanced issues. It focuses on


Working With Projects

The IDE organizes the work you do into a project, using a default project if you do not explicitly set up a project. A project organizes the files that are required to produce a MIDlet application. By organizing your files into a project, you can operate on the files as a whole. For example, when you compile a project, you compile all of the MIDlet files and Java source files in it.

Most importantly, a project organizes the settings for your MIDlets. These include code completion and settings for the default compiler, executor, and debugger.

You create and manage projects using the Project menu in the main window.

To view the files in the current project:

single-step bulletClick the Project tab in the Explorer window.

The Project tab is labeled with the name of the current project.


Creating a New Project

To create a new project:

1. In the main window, choose Project right arrow Project Manager.

The Project Manager window opens.

When you open the Project Manager, it displays existing projects. (Note that the tool always has at least one default project, labelled Project Default.) You can open projects, delete projects that are not open, and rename existing projects in the Project Manager window.

2. From the Project Manager window, choose New.

Screenshot showing the Project Manager window. Buttons are Close and Help. 

3. In the Create New Project dialog box, type CurrencyConverter as the name of the new project and click OK.

The IDE creates a new project named CurrencyConverter. The Project Configuration wizard opens.

Screenshot showing the Create New Project dialog box. Buttons are OK and Cancel. 

4. In the Project Configuration wizard, select the Mobile Information Device Profile CLDC/MIDP configuration and click Finish.

Configuring the project sets its default compiler, executor, debugger, and Java source code completion. Each project can have its own configuration.

Screenshot showing the project configuration wizard. Buttons are Finish and Help. 

5. Select the Filesystems tab. Right-click the Filesystems node and choose Mount right arrow Local Directory to mount filesystems (directories) that contain source files or other objects that you want to include in your project.

This opens the Local Directory wizard, where you can select filesystems to mount. You must mount filesystems so that their contents are available to the project manager.

6. Select the Project tab in the Explorer window. Right-click the project name and choose Add New to add new components to the project or choose Add Existing to add existing components to the project.

The Explorer's Project tab displays the name of the current open project. When you first create a project, Mobile Edition IDE opens that project. When you add a new component to the project, you first select a template from the list of available templates, such as a MIDP right arrow MIDlet or MIDP right arrow MIDlet Suite. The appropriate wizard guides you through the steps to create that particular component.

Screenshot showing the Explorer window's Project tab with Add New selected. 

7. Compile or build and execute your code.

Use the Project's contextual menu to compile and build the application and to execute it.


Setting Emulators

The Mobile Edition IDE helps you develop MIDP applications that are intended to be used on wireless devices such as mobile phones. Running the application on its intended device is an important part of developing and testing an application. To help with this process, the Mobile Edition IDE maintains a device emulator registry from which you choose an emulator for testing an application. The registry lists the installed emulators that are available to you and identifies the currently established default emulator.

To add an emulator to the Device Emulator Registry:

1. Install the emulator on your system according to the emulator vendor's instructions.

2. In the Explorer window, expand the Device Emulator Registry node. Right-click Installed Emulators and choose Add Emulator.

Screenshot showing the Add Emulator option. The callout indicates the Runtime tab. 

3. From the Select emulator installation directory dialog box, navigate to the directory that contains the emulator. Then click Add.

For the J2ME Wireless Toolkit emulator included with Mobile Edition, the directory is ffj_install\emulator\j2mewtk-1_0_3-xxx.

Screenshot showing the Select emulator installation directory dialog box. The buttons are Add and Cancel. 

4. To add an additional instance of an emulator, expand the Installed Emulators node. Right-click an installed emulator and choose Add Emulator Instance.

Adding additional instances of an emulator lets you change the properties or the default emulator device that will display the executed MIDlet for that emulator instance. You can then choose the device emulator to execute your application through the Execution tab of the MIDlet suite property sheet, rather than going to the Device Emulator Registry each time you want to test your application under different conditions.

5. Right-click on the second instance and choose Properties. Then click in the Default device field and choose MinimumPhone from the combo box.

The MinimumPhone skin is now the default device for the second instance of the J2ME Wireless Toolkit Emulator. Notice that you can install multiple versions of the same emulator as well as different emulators.

6. Add two more instances of the Emulator and set a different default device for each emulator instance.

This adds a third and fourth instance of the J2ME Wireless Toolkit Emulator. These subsequent versions are numbered 3 and 4.

Screenshot showing the four installed emulators in the Explorer window. 

7. In the Filesystems tab of the Explorer, right-click on a MIDlet suite node and select Properties.

8. Select the Execution tab, and click on the Emulator field.

The combo box shows you a list of the device emulators you can choose from to execute and test the MIDlet suite. Try executing the MIDlet suite to see how the results differ with each emulator.


Supporting Over-the-Air (OTA) Application Downloading

Over-the-Air (OTA) is a technology for user-initiated provisioning.The name of this technology refers to the ability of a wireless device, such as a mobile phone, to download applications from a special portal or server that hosts the applications. The download is accomplished without a physical connection between the wireless device and the host server or portal. OTA gives users the ability to access desired services "over the air" at almost any time and place.

While Mobile Edition IDE does not have explicit OTA support, there are certain steps you can take to implement OTA for your MIDlet suite. These steps enable you to deploy a MIDlet suite to a provisioning server, and then create a download page for that MIDlet suite.

To enable over-the-air downloading capabilities:

1. Set the Internal Compiler Debug property to False and compile the MIDlet code without debugging information.

You should optimize the MIDlet code before packaging and deploying it. Do this by recompiling the MIDlet code without debugging information. Recall that you set the Internal Compiler's Debug property to False and then recompile the source code. You can find the Internal Compiler from the Tools right arrow Options window, within the Building right arrow Compiler Types node. See Deploying a MIDlet Suite.

2. Rebuild the JAR file.

See Packaging a MIDlet Suite for instructions on rebuilding the JAR file.

3. Configure your web server by adding the correct MIME types for serving JAD files.

Use the following URL to be sure that the correct MIME types are set for a server:

http://host:port/servlet/org.netbeans.modules.j2me.jam.JAMServlet/path_to_jad

For example, an installation might set the URL as follows:

http://localhost:8083/servlet/org.netbeans.modules.j2me.jam.JAMServlet/converter.jad

MIDP applications can also be downloaded from Mobile Edition IDE's internal http server. For more information on MIME types, see the OTA specification, which can be found at
http://java.sun.com/products/midp/OTAProvisioning-1.0.pdf.

4. Create a download page for the MIDlet suite.

Use your preferred HTML tool to create the download page.

The next step is to use the file transfer protocol (FTP) to copy a MIDlet suite and deploy it to another location. The suite and its accompanying application descriptor file are sent to the FTP site you designate. Before you can use the file transfer protocol to deploy the MIDlet suite, you must first set up an FTP copy service as an executor option.

5. From the main window, choose Tools right arrow Options, expand the Debugging and Executing node, and then expand the Execution Types node. Select "FTP to <> on <localhost>" copy executor. Then, enter values for the FTP Properties.

Screenshot showing the properties for the FTP copy function. Buttons are Close and Help. 

6. Set values for the four FTP copy properties.

Set the FTP properties as follows:

When you have entered these four values, click Close.

7. To deploy the application, select the MIDlet suite in the Explorer window and choose Tools right arrow Copy File. The Select Target dialog box opens. Select "FTP to <d:\midlets\downloadsite> on <localhost>" and click OK.

Screenshot showing the target settings for the FTP copy executor. Buttons are OK and Cancel. 

The application is sent to the specified FTP site.

8. Download the MIDlet application to a real device.

Currently, you cannot download an OTA application to an emulator.


Deploying a MIDlet Suite

Before you deploy the application, you need to recompile the application with debugging turned off. This reduces the final code to its smallest size. Normally, you take this step after completing the debugging process. (See Chapter 2 for instructions on how to debug your program.)

While you are developing and testing applications, you should have Mobile Edition IDE's preverifier compiler set so that its Java compiler uses internal compilation. This setting enables you to use the debug functionality. When you have completed testing the application, you remove this debug functionality by turning off the internal compilation's debug property and recompiling the code.

Keep in mind that by default, the preverifier compiler uses internal compilation. This means that you might have to remove debug functionality and recompile the code even if you did not explicitly debug your program.

To deploy a MIDlet suite:

1. From the main window, choose Tools right arrow Options right arrow Building right arrow Compiler Types and then right-click Internal Compilation to see its property sheet.

In the property sheet, click the Debug combo box and set its value to False.

Screenshot showing the internal compilation settings.Buttons are Close and Help. 

2. Recompile all the source code and update the JAR file.

Before compiling the source code, you might want to use the Build right arrow Clean or Build right arrow Clean All options (from the main window) to ensure that the compiler does recompile all classes. The application is now compiled and packaged with no debug additions and is ready to be deployed.