Packaging a MIDlet

Following the above steps is sufficient to build simple MIDlets for running in the emulator. However, if you are developing a more sophisticated MIDlet that contains many classes, images, application parameters, and so on, you need to package your MIDlet into a MIDlet suite.

Packaging creates a JAR file containing all your class and resource files (such as images and sounds) and the application descriptor (JAD) file, which notifies the AMS of the contents of the JAR file.

The following attributes must be included in a JAD file:

• MIDlet-Name: the name of the suite that identifies the MIDlets to the user

• MIDlet-Version: the version number of the MIDlet suite; this is used by the AMS to identify whether this version of the MIDlet suite is already installed or whether it is an upgrade, and communicate this information to the user

• MIDlet-Vendor: the organization that provides the MIDlet suite

• MIDlet-Jar-URL: the URL from which the JAR file can be loaded, as an absolute or relative URL; the context for relative URLs is the place from where the JAD file was loaded

• MIDlet-Jar-Size: the number of bytes in the JAR file.

The following attributes are optional but are often useful and should be included:

• MIDlet-n: the name, icon and class of the nth MIDlet in the JAR file (separated by commas); the lowest value of n must be 1 and all following values must be consecutive; the name is used to identify the MIDlet to the user and must not be null; the icon refers to a PNG file in the resource directory and may be omitted; the class parameter is the name of the class extending the MIDlet class

• MIDlet-Description: a description of the MIDlet suite

• MicroEdition-Configuration: the Java ME configuration required, in the same format as the microedition.configuration system property, for example, 'CLDC-1.0'

• MicroEdition-Profile: the Java ME profiles required, in the same format as the microedition.profiles system property, that is'MIDP-1 0'or'MIDP-2.0'; if the value of the attribute is'MIDP-2.0', the target device must implement the MIDP profile otherwise the installation will fail; MIDlets compiled against MIDP 1.0 will install successfully on a device implementing MIDP 2.0.

The following is the JAD file for our HelloWorld application:

MIDlet-1: HelloWorldMIDlet,,example.HelloWorldMIDlet MIDlet-Description: Example MIDP MIDlet MIDlet-Jar-Size: 1042 MIDlet-Jar-URL: HelloWorld.jar MIDlet-Name: HelloWorld Midlet Suite MIDlet-Vendor: Midlet Suite Vendor MIDlet-Version: 1.0.0

MicroEdition-Configuration: CLDC-1.1 MicroEdition-Profile: MIDP-2.0

You can automate the task of creating the JAD file by clicking Package/Create Package in the WTK menu. The WTK creates HelloWorld.jar and HelloWorld.jad in the bin folder of your project root. You can use Windows Explorer to browse to that folder and check that the package files have been correctly created. You can open the JAD file with a standard text editor to inspect its contents. Double-clicking the JAD file executes your application in the emulator (see Figure 2.4).

0 0

Post a comment

  • Receive news updates via email from this site