Packaging Your Application

Team-Fly

You won't pass class files directly to a MID to deploy an application. Instead, you'll package them in a Java Archive (JAR) using the jar tool that comes with the Java 2 SDK.

If you're using the J2ME Wireless Toolkit, you won't ever have to perform these steps manually; the toolkit automatically packages your MIDlets. Nevertheless, you might want to read through this section so you understand exactly what's going on.

If you're using the MIDP reference implementation, you should follow these steps to package your MIDlets.

We'll only sketch the steps here; in the next chapter you'll learn all the gory details of MIDlets and MIDlet suites.

Manifest Information

Every JAR includes a manifest file, META-INF\MANIFEST.MF, that describes the contents of the archive. For MIDlet JARs, the manifest file should contain extra information. The extra information is stuff that's important to the MIDP runtime environment, like the MIDlet's class name and the versions of CLDC and MIDP that the MIDlet expects.

You can specify extra manifest information in a simple text file and tell the jar utility to include that information in the manifest when the JAR is created. To package Jargoneer, for example, save the following text in a file named extra.mf:

 MIDlet-1: Jargoneer, , Jargoneer MIDlet-Name: Jargoneer MIDlet-Vendor: Sun Microsystems MIDlet-Version: 1.0 MicroEdition-Configuration: CLDC-1.0 MicroEdition-Profile: MIDP-1.0 

Now assemble the MIDlet classes and the extra manifest information into a JAR with the following command:

 jar cvmf extra.mf Jargoneer.jar Jargoneer.class Jargoneer$Poster.class 

With J2MEWTK, the toolkit automatically assembles your application into a MIDlet suite JAR when you press the Build button. It's very convenient, and it saves you from the effort of learning the jar tool.

Creating a MIDlet Descriptor

One additional file is needed before your MIDlet is ready to go out the door. An application descriptor file must be created. This file contains a lot of the same information that's in the MIDlet JAR manifest file. However, it lives outside the JAR and enables application management software to learn about a MIDlet JAR without installing it.

The application descriptor is a text file with a .jad extension. Type in the following and save it as Jargoneer.jad:

 MIDlet-1: Jargoneer, , Jargoneer MIDlet-Jar-Size: 3853 MIDlet-Jar-URL: Jargoneer.jar MIDlet-Name: Jargoneer MIDlet-Vendor: Sun Microsystems MIDlet-Version: 1.0 

The MIDlet descriptor is automatically generated when you press the Build button in the J2MEWTK. If you're using the J2MEWTK, you won't need to create the application descriptor yourself.

Running the Packaged Application

If you're using the MIDP reference implementation, you'll need to use some command options to tell the midp emulator about your application descriptor and MIDlet JAR:

 C:\>midp -descriptor Jargoneer.jad -classpath Jargoneer.jar 

Or, in the J2MEWTK, just select the emulator you want and press the Run button.


Team-Fly


Wireless Java. Developing with J2ME
ColdFusion MX Professional Projects
ISBN: 1590590775
EAN: 2147483647
Year: 2000
Pages: 129

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net