Downloading the J2ME Wireless Toolkit

Now that you know your way around the J2ME landscape, let’s get started with J2ME. However, before we can compile and run any J2ME programs, we need to download and install the J2ME Wireless Toolkit. You can obtain the J2ME Wireless Toolkit at the following URL: http://java.sun.com/products/j2mewtoolkit.

The version that we use in this book is 1.0.3 beta. It is available for the Microsoft Windows 98/ME and 2000 platforms, as well as Linux and Sun Solaris operating systems. The toolkit requires the presence of at least Version 1.3 of the Java Development Kit (JDK) for the host operating environment.

Once you’ve downloaded the Wireless Toolkit, double-click on it or execute the resulting binary (depending on your platform) to activate the extraction. This will uncompress the files needed to install the Wireless Toolkit. Note that you may be directed to specify an existing JDK installation on your system. If so, choose the latest stable release of the JDK that you currently have on your system.[4] In addition, the distribution may also ask you if you would like to install a version of the toolkit that interfaces with Forte™ for Java. If you would like to develop your J2ME applications in the Forte for Java Integrated Development Environment, choose the corresponding option. Be sure that Forte is already installed on your system before doing so.

In this case, we’re going to install the Java Wireless Toolkit on a Windows platform into the directory C:\j2mewtk. After the installation is completed, this directory will contain all the required classes and tools to run the MIDP applications. (If the installation program asks you to run the ktoolbar program, just ignore it for the moment.) However, we need to do a few more things before we can get started with our examples.

First, we need to add the wireless toolkit binaries to your system path. You can do that on Windows with the following command (again, we’ve assumed that the Java Wireless Toolkit is installed at C:\j2mewtk):

SET PATH=%PATH%;C:\j2mewtk\bin

If you edit your C:\AUTOEXEC.BAT file to add this to the default system path, as shown below, and restart your machine, then you will not have to repeatedly perform this step each time you restart your system.

With Linux and Solaris, the equivalent command is:

export PATH=$PATH:install_directory/j2mewtk/bin

Once you’ve added that directory to your system path, you should be able to run the Java Wireless Toolkit tools from any directory on your system. An easy way to test it is to execute the preverify command, without any arguments. You should see output similar to the following:

C:\> preverify
Usage: PREVERIFY.EXE [options] classnames|dirnames ...

where options include:
   -classpath <directories separated by ';'>
                  Directories in which to look for classes
   -d <directory> Directory in which output is written 
   @<filename>    Read command line arguments from a text file.

In order for the toolkit to work properly, you’ll need to have the J2SE tools (notably javac) available on your system executable path as well. Instructions on how to do this are bundled with the JDK, although it really boils down to adding the binary path of the J2SE binaries to your system path.

Tip

If you’re familiar with the J2ME Wireless Toolkit already, you’re likely wondering why we’re not using KToolbar. We’ll cover KToolbar in Chapter 4. In the meantime, it helps to see how J2ME works under the hood.

To compile and run J2ME programs from the command line, enter the following commands. Again, feel free to set these system environment variables on the command line, or edit the AUTOEXEC.BAT file (or similar) on your system for convenience.

SET J2MEWTK_HOME=C:\j2mewtk
SET MIDPAPI=%J2MEWTK_HOME%\lib\midpapi.zip
SET J2MECLASSPATH=%J2MEWTK_HOME%\wtklib\kenv.zip;
    %J2MEWTK_HOME%\wtklib\kvem.jar;%J2MEWTK_HOME%\wtklib\lime.jar

On the Linux and Solaris side, the following could be added to your .profile (or equivalent):

export J2MEWTK_HOME=/home/qmahmoud/j2mewtk
export MIDPAPI=$J2MEWTK_HOME/lib/midpapi.zip
export J2MECLASSPATH=$J2MEWTK_HOME/wtklib/kenv.zip:
    $J2MEWTK_HOME/wtklib/kvem.jar:$J2MEWTK_HOME/wtklib/lime.jar

Note the that final line in either case is really one line; it’s been continued here for clarity.



[4] Try to use a JDK instead of just a Java Runtime Environment (JRE). It’s important that you have the javac compiler to create J2ME applications.

Get Wireless Java now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.