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


AddThis Social Bookmark Button

MIDlet Packaging with J2ME
Pages: 1, 2, 3, 4, 5

Here is an example of a simple manifest file:

MIDlet-Name: Rogue
MIDlet-Version: 1.0
MIDlet-Vendor: My Corporation Inc.
MIDlet-1: rogue, /images/rogue.png, rogue.rogueMIDlet
MicroEdition-Profile: MIDP-1.0
MicroEdition-Configuration: CLDC-1.0

Java Application Descriptor File

Although not required, you should typically include a JAD file along with the JAR. As with the manifest, this file contains information about a MIDlet. There are two reasons to create a JAD.

  • To provide information to the application manager about the contents of a JAR file. With this information, decisions can be made as to whether or not a MIDlet is suitable for running on the device.

    As an example, by looking at the attribute MIDlet-Data-Size, the application manager can determine if the MIDlet requires more persistent memory than the device can provide.

  • To provide a means for parameters to be passed to a MIDlet without having to make changes to the JAR file. We'll see an example of this as we progress through the article.

The JAD files uses the same attributes as in Table 1. If you need to create your own attributes, you can do that as well. As long as you use attribute names that do not begin with MIDlet- you're all set. An example of a custom attribute is shown below in the file showProperties.jad.

As with the manifest, there are certain attributes that must be defined. If not available, the application manager will not load the MIDlet.

  • MIDlet-Name
  • MIDlet-Version
  • MIDlet-Vendor
  • MIDlet-<n> for each MIDlet
  • MIDlet-Jar-URL
  • MIDlet-Jar-Size

The values of MIDlet-Name, MIDlet-Version, and MIDlet-Vendor must be identical to the value of the same attributes in the JAR's manifest. As you might guess, if there is a difference in the files, the application manager will not load the JAR.

If any other attributes names are duplicated in both files, and the values of those attributes are not the same, the application descriptor file (JAD) attributes will take precedence.

The 1.0 MIDP specification does not show the MIDlet-n attribute as one that is required in the JAD file. However, without this entry, I was not able to preview MIDlets in the device emulator. Including this attribute in both files is not a problem, and, actually, doing so may provide more clarity as to how these files are related. Thus, for completeness, all examples here will include the MIDlet-n attribute inside the JAD.

A very simple JAD file might look like

MIDlet-Name: Memo Pad
MIDlet-Version: 1.0
MIDlet-Vendor: My Corporation Inc.
MIDlet-Jar-URL: http://www.yourweb.com/MIDlets/memopad.jar
MIDlet-Jar-Size: 26248
MIDlet-1: MemoPad, /images/MemoPad.png, MemoPad.Main

Accessing JAR/JAD attributes from a MIDlet

A MIDlet can access all the attributes defined inside both the manifest file (which is part of a JAR) and those inside the JAD file. The complete package name to the method that will return information about the properties is

javax.microedition.midlet.MIDlet.getAppProperty(String name)

Pages: 1, 2, 3, 4, 5

Next Pagearrow