ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

MIDlet Packaging with J2ME

by John W. Muchow
04/26/2001

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.

Note: Learning about JAR files
Visit Sun's Java Tutorial online for more information about jar files:

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

Inside our "Game Pack" example, we may have two entries:
  MIDlet-1: Rogue, /images/rogue.png, rogue.rogueMIDlet
  MIDlet-2: Golf, /images/golf.png, golfMIDlet

MIDlet-Jar-URL URL of the JAR file
MIDlet-Jar-Size The JAR file size in bytes
MIDlet-Data-Size The minimum number of bytes required for persistent data storage.
MicroEdition-Profile What J2ME Profile is required by the MIDlet
MicroEdition-Configuration What J2ME Configuration is required by the MIDlet.

These attributes are not all required. However, without the following six, the application manager is required to refuse to load the JAR.

  • MIDlet-Name
  • MIDlet-Version
  • MIDlet-Vendor
  • MIDlet-<n> for each MIDlet in the JAR file
  • MicroEdition-Profile
  • MicroEdition-Configuration

Pages: 1, 2, 3, 4, 5

Next Pagearrow