Sun Java Solaris Communities My SDN Account Join SDN
 
Article

MIDP Setup Explained

 



MIDlets are small applications written in the Java programming language that run in all mobile phones and two-way pagers that support the Mobile Information Device Profile (MIDP). To create and test MIDlets, to install the software, configure your system, and create a descriptor file for the MIDlet. This article explains how and concludes with instructions on compiling and running the HelloMIDlet example used in the article Introduction to Wireless Programming with the MID Profile.

Installing the Software

Currently, Windows is the only platform on which the MIDP reference implementation is certified; however, the Connected Limited Device Configuration (CLDC) is available for the Windows and Solaris platforms, and the JDK platform is available for Windows, Solaris, and Linux.

To write MIDlets, download and install the following software for the Windows platform:

.
. . .
. Note: You need the JDK platform to use the javac command to compile MIDlets. .
.
.

Download and unzip the above software in the following recommended directory structure:

C:\JDK1.2
C:\j2me
|
MIDP
|
CLCD

This article assumes that directory is C:\j2me.

You do not need to build your own environment unless you are going to port your applications to other platforms. The MIDP and CLDC downloads require minimal setup to develop and test applications with the MIDP software.

Setting Up



check settings
Check Settings

To set up your environment to locate class files, tools, and commands, update your path settings to point to the MIDP and JDK workspaces.

Set Environment Variables

Set the PATH environment variables on the Windows:

  1. Open the AUTOEXEC.BAT file in your root directory in a text editor, or type sysedit in Run from the Start button.
  2. Insert the following, typing the PATH on one line:

    This example assumes C is the main drive and the one on which the JDK is installed.
    SET PATH=%PATH%;%JAVAHOME%\BIN;
    PATH=C:\WINDOWS;C:\WINDOWS\COMMAND;C:\JDK\BIN;
    C:\j2me\midp\bin;%PATH%
    

Check Environment Variable Settings

  1. Check your settings by typing the following on the command line:
    C:\midp
    
  2. Press Enter.

    The phone image on the left should pop up in your window.
check settings
Color Display

Set Screen Depth for Color Display

  1. Check your color depth by typing this command on the command line:
    C:\set SCREEN DEPTH=8
    
  2. Press Enter then type:
    C:\midp -descriptor run.jad
    

The phone image at the right appears in your window. You are now ready to develop and test an MIDP application.

Writing the Descriptor File for HelloMIDlet

The descriptor file to run the HelloMIDlet example from the Introduction to Wireless Programming with the MID Profile article looks like this:

MIDlet-Name: HelloMIDlet
MIDlet-Version: 1.0.0
MIDlet-Vendor: Sun Microsystems, Inc.
MIDlet-Description: A Simple Example
MIDlet-Info-URL: http://java.sun.com/j2me/
MIDlet-Jar-URL: hello.jar
MIDlet-Jar-Size:    1063
MicroEdition-Profile: MIDP-1.0
MicroEdition-Configuration: CLDC-1.0
MIDlet-1: HelloMIDlet,, HelloMIDlet

Compiling, Preverifying, Packaging, and Running HelloMIDlet

Before running your program, compile, preverify, and package your MIDlet.

Compiling

To compile the HelloMIDlet example, cd to the directory where you saved the .java file, then type the following on one line:

C:\javac -d .\ -bootclasspath
c:\pathTo\MIDP\classes HelloMIDlet.java

Preverifying

This command preprocesses the program for use by the K virtual machine (KVM) without changing the name of a class. Skipping this step will produce an error if you try to run your application.

To process with preverify, type preverify with -classpath, followed by the path to the midp classes, then the path to the directory where you compiled the FirstMIDlet file. For instance, if you saved and compiled the FirstMIDlet.java file in C:\Examples, the preverify command is written as:

C:\preverify -classpath c:\j2me\MIDP\classes;
C:\Examples\ FirstMIDlet

A preverified class file is written to the directory C:\Examples\output\

Test the example from the C:\Examples\output\ directory by typing the following on the command line:

C:\Example\output>midp FirstMIDlet

Packaging

To package the HelloMIDlet example, put the HelloMIDlet class file into a JAR file as follows:

C:\jar cf hello.jar HelloMIDlet.class

Running

To execute the example, type the following:

C:\midp -descriptor hello.jad

You can find more information on descriptor files, and how to run and test MIDlets in the article Wireless Application Programming: MIDP Programming and Packaging Basics.




Reader Feedback
Excellent   Good   Fair   Poor  

If you have other comments or ideas for future technical tips, please type them here:

Comments:
If you would like a reply to your comment, please submit your email address:
Note: We may not respond to all submitted comments.

Have a question about Java programming? Use Java Online Support.



Back To Top