MIDlet Packaging with J2MEby John W. Muchow
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).
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
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.
||Name of the MIDlet "package". For example, "Game Pack"|
||Version number of the MIDlet|
||Who created the MIDlet|
||Icon associated to show alongside the MIDlet-Name by the application manager. This is a graphics file stored as a PNG image.|
||Text describing the MIDlet|
||URL that may have more information about the MIDlet and/or the vendor|
This attribute contains up to three pieces of information:
Inside our "Game Pack" example, we may have two entries:
||URL of the JAR file|
||The JAR file size in bytes|
||The minimum number of bytes required for persistent data storage.|
||What J2ME Profile is required by the MIDlet|
||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-<n>for each MIDlet in the JAR file