MIDlet Packaging with J2ME

In last months article, J2ME and MIDP
Development, we covered the basics of Java 2 Micro Edition (J2ME)
and the Mobile Information Device Profile (MIDP). We touched upon
installation, configuring the environment, writing a simple MIDlet, as
well as compiling, pre-verifying class files, and running a MIDlet on
a mobile device emulator.

This article takes the next logical step: packaging MIDlets. It
includes an introduction to the MIDlet Suite, including Java archive
and application descriptor files. To put all this into practice,
we'll write two short MIDlets and create a JAR and JAD to package
these programs. We also look at how using Java packages changes our
development process slightly. And, finally, interweaved with the
development of the MIDlets in this article, you'll learn how to access
MIDlets from a web server.

The MIDlet Suite

Although it's not a requirement to place MIDlets inside a Java
Archive (JAR) file, this will be the most common means of distributing
J2ME/MIDP applications. The MIDlet Suite is the name given to the
entire collection of all files and resources that may be required as
part of a MIDlet. The MIDlet Suite consists of

Java class files enclosed in a JAR file,

manifest file describing the contents of the JAR,

resources (images, etc) enclosed in a JAR file, and

Java Application Descriptor file (JAD).

Application Manager

The application manager is a software program on the mobile
device. This application is device dependent and implemented by the
manufacturer of the device. It's responsible for installing, running,
and removing MIDlets from the device. It provides error-handling
support. The application manager may also provide an optional
interface to allow users to start, stop, and delete MIDlets.

Java Archive File

A production, packaged application will generally consist of many
files. In addition to Java classes, other files such as images and
application data, known as resources, may be part of the package. You
bundle all this information together into a single entity, a JAR
file.

In addition to class and resource files, a JAR contains a manifest
file which describes the contents of the JAR. The manifest has the
name manifest.mf and is stored in the JAR file
itself. The table below lists all available attributes that may be
defined within the manifest file.

Table 1

Attribute

Purpose

MIDlet-Name

Name of the MIDlet "package". For example, "Game Pack"

MIDlet-Version

Version number of the MIDlet

MIDlet-Vendor

Who created the MIDlet

MIDlet-Icon

Icon associated to show alongside the MIDlet-Name by the application
manager. This is a graphics file stored as a PNG image.

MIDlet-Description

Text describing the MIDlet

MIDlet-Info-URL

URL that may have more information about the MIDlet and/or the
vendor

MIDlet-<n>

This attribute contains up to three pieces of information:
 MIDlet name
 Icon for this MIDlet (optional)
 Class name the application manager will call to load this MIDlet