Website - J2ME Enterprise Development

About MSales

The MSales application is the centerpiece of Part II in this book.  It's used to illustrate the APIs covered earlier in the book from the context of a real-world appliction.   MSales:

Known Bugs

MSales Download File

The J2ME_MSales.zip file contains the source code and binary distribution of the latest MSales code.  Inside you will find the following directories contained in a root MSales directory:

Unzip this file to wherever you want, for example I unzipped it to my C:\ drive.

Setting up the MSales Client and Server

Overview:

The process to install a working copy of MSales on your computer includes many steps but it is actually quite easy to do.  We developed MSales on desktops running Windows 2000 but you could modify the process below for other platforms.  The only component tied to Windows is the Access database for the MSales server.  The reason we chose Access was that many people using Microsoft Office already have it installed.  Given the platform agnostic nature of any Java application you may want to move your development to a cross platform database such as MySQL.  Instructions on using alternative databases will be posted separately to the website and alternative options to other components will be mentioned throughout the guide below.

 

MSale's setup can be divided into three phases.  First, I will go through all the software you need to install on your development machine in order to run MSales.  Next, I'll show you how to run the precompiled version of MSales included in this download.  Finally, MSales can be recompiled and repackaged from the source code.  All three phases are described below.

 

Step 1: Software Installation

MSales makes use of several tools for both the server and client applications, most of which are freely available.  Here's the complete list of what you'll need as a minimum (and some sources for alternatives):

 

Download

Purpose

Location

J2SE 1.3.1

The Standard Edition of Java, you may also download the most recent J2SE 1.4 release (the book used the Java Debugger included with J2SE 1.4 SDK).

http://java.sun.com/j2se/1.3/

Tomcat

The Servlet engine that runs the MSales server component.  This install includes the necessary libraries to build Servlets.  Alternatively you can download the latest J2EE developers kit (or another servlet engine) but I won't cover that here.

http://jakarta.apache.org/tomcat/index.html

MS Access (or another database such as MySQL)

We used MS Access as the backend database for the MSales server.  You could also use another database, such as My SQL, although the binary database file included in the download is in Access format.

http://www.microsoft.com/

or

http://www.mysql.com/

Forte for Java Community Edition
(optional)

Forte provides a nice IDE for creating, testing, and running MIDlets such as MSales.  If you install Forte be sure to do so before installing the Wireless Toolkit.  You can then install the "integrated" version of the Toolkit which adds MIDP functionality to the IDE.  Alternatively you can use your favorite IDE or text editor.  Forte simplifies the process of creating MIDlets and provides detailed documentation.  For that reason I won't cover its use and configuration in this document.

http://www.sun.com/forte/ffj/

The J2ME Wireless Toolkit

Provides the tools, such as the emulator and preverifyer, needed to build MIDP applications.

http://java.sun.com/products/j2mewtoolkit/

Palm OS Emulator and ROM images

(optional)

Used in conjunction with the Wireless Toolkit to run MIDP applications, like MSales, on a Palm OS emulator.  We chose to develop MSales for the Palm but you could also just use the phone emulator provided in the toolkit if you like.  If you do use the Palm OS Emulator make sure you obtain a ROM image from the Palm developers program.  This process involves a registration and an easy application.  Configuring the Palm OS Emulator is described in great detail in Appendix A of the book.

http://www.palmos.com/dev/tools/

 

Install this software in the order given above.  Forte is optional and MS Access as the backend database can be substituted with My SQL if you prefer.   Any other third party Servlet container can be used in place of Tomcat including the J2EE reference implementation available from Sun.  Once you've installed all this software you're ready to move onto the next step.

 

Tip: A tag like <something_install_dir> refers to the directory that you installed that tool in.  Replace it with the actual location when needed below.

 

Step 2: Configure Tools

The next step is to verify that the components you just installed are working correctly.  At this time it's probably a good idea to make sure your environmental variables are set up correctly.   Setting the PATH variable allows you to compile and execute the emulator from your current working directory.  The other variables are used by Tomcat.

 

Tip: To set these variables in Windows 2000 right-click on the "My Computer" icon and choose "Properties."  Then choose the "Advanced" tab and click on the "Environmental Variables" button.  You can then choose to add or modify the environmental variables (which are in caps such as "PATH").  On a Unix machine modify these variables in your shell script (such as the .cshrc file) in your home directory.  Remember that Unix (Linux) and Windows machines use slashes differently ("/" and "\" respectively).

 

The following variables need to be set:

 

Variable

Value

Reason

CATALINA_HOME

<Tomcat_Install_Dir>

used by Tomcat to locate it's install directory

JAVA_HOME

<J2SE_Install_Dir>

used by Tomcat to locate the Java home directory

PATH

<J2SE_Install_Dir>\bin;
<Tomcat_Install_Dir>\bin;
<Toolkit_Install_Dir>\bin;

J2SE commands
Tomcat executables
Toolkit executables

 

Step 3: Set up the MSales Server

This step assumes you're installing MSales Server on the same machine you're running the emulator on.  The server installation starts with verifying Tomcat is installed properly.

Check Tomcat

Install the Server Files

These next steps will put the server files in the correct place.

 

Step 4: Setup the Emulator

Now that the server is working the next step is to get the emulator included with the Wireless Toolkit linked to the Palm OS emulator.  When we developed MSales we had PDAs in mind.  Alternatively you can skip this step and just use the emulator cellphone "skins" included in the Toolkit emulator but I think it's more effective to use the Palm OS version.

 

Step 5: Run the precompiled MSales

At this point the MSales Server is working and the Wireless Toolkit emulator has been configured to use the Palm OS emulator.  The next step is to launch the precompiled version of MSales before trying to build your own.  Make sure Tomcat is running before continuing. There are two ways to launch the application:

 

Step 6: Building MSales

In the previous steps we used the precompiled files (.jar and .jad) to launch the MSales application.  This step looks at recompiling the MSales client and server from the source files in the <MSales_Install_Dir>\src directory.

Tip: It might be easies to use an IDE like Forte to compile and preverify.  The advantage of the command line utilities is their ability to be automated using the make command for example.

 

Step 7: Package MSales

The previous step looked at compiling the client (and server) source code.  In order to run the MSales MIDlet the client code needs to also be put in a jar file with a jad file description.  This section looks at the packaging needed to complete an application.

You should now have a finished, updated MSales.jar file in the bin directory that you can load and run by following the previous instructions.

Helpful Web Links

Here are some useful websites for J2ME and related technologies.

Technical Sites

-         www.microjava.com

-         www.javaworld.com

-         www.ibm.com/developerworks

-         theserverside.com

Third Party Tools

-         xml.apache.org

-         www.ashnasoft.com

-         www.mysql.com

-         jakarta.apache.org

Sun Sites

-         wireless.java.sun.com

-         java.sun.com

-         java.sun.com/products/j2mewtoolkit

-         java.sun.com/products/midp