![]() |
![]() |
MIDlet Instructions |
![]() |
This document describes how to quickly get up and running developing
MIDlets with this release of the Mobile
Information Device Profile (MIDP), JSR-037. These instructions assume
you already have a midp executable and a set of preverified class
files to use. e.g. a lib/midp.jar file or a classes.zip
file (or the classes subdirectory) can be interchanged whenever
the -bootclasspath or -classpath command line arguments
are needed.
MIDlet ProgramFirst create your MIDlet program. (See src/example. )Hello world MIDlet: import javax.microedition.midlet.*; import javax.microedition.lcdui.*; /** * An example MIDlet with simple "Hello" text and an Exit command. * Refer to the startApp, pauseApp, and destroyApp * methods so see how each handles the requested transition. */ public class HelloMIDlet extends MIDlet implements CommandListener { private Command exitCommand; // The exit command private Display display; // The display for this MIDlet public HelloMIDlet() { display = Display.getDisplay(this); exitCommand = new Command("Exit", Command.SCREEN, 2); } /** * Start up the Hello MIDlet by creating the TextBox and associating * the exit command and listener. */ public void startApp() { TextBox t = new TextBox("Hello MIDlet", "Test string", 256, 0); t.addCommand(exitCommand); t.setListener(this); display.setCurrent(t); } /** * Pause is a no-op since there are no background activities or * record stores that need to be closed. */ public void pauseApp() { } /** * Destroy must cleanup everything not handled by the garbage collector. * In this case there is nothing to cleanup. */ public void destroyApp(boolean unconditional) { } /* * Respond to commands, including exit * On the exit command, cleanup and notify that the MIDlet * has been destroyed. */ public void commandAction(Command c, Displayable s) { if (c == exitCommand) { destroyApp(false); notifyDestroyed(); } } } Compiling the MIDletTo compile any programs written for the MIDP platform, enter the following:mkdir -p tmpclasses javac -d classes -classpath classes src/example/HelloMIDlet.java Preverifying the MIDletAfter compiling your program it must be processed by the preverify command. This command must be run from your chosen platform's directory (either build/linux, build/solaris or build/win32) so the classes/ subdirectory exists and contains compiled Java classes.bin/preverify -classpath classes -d classes tmpclasses MIDlet Descriptor File, Jar File Manifest, OTA listingCreate a descriptor file for the MIDlet (hello.jad)MIDlet-Name: HelloWorld MIDlet-Version: 1.0.0 MIDlet-Vendor: Sun Microsystems, Inc. MIDlet-Description: Sample Hello World MIDlet MIDlet-Info-URL: http://java.sun.com/j2me/ MIDlet-Jar-URL: http://<host>/<path>/hello.jar MIDlet-Jar-Size: 1020 MicroEdition-Profile: MIDP-1.0 MicroEdition-Configuration: CLDC-1.0 MIDlet-1: HelloWorld,, HelloMIDlet MIDlet-Name: HelloWorld MIDlet-Version: 1.0.0 MIDlet-Vendor: Sun Microsystems, Inc. MicroEdition-Profile: MIDP-1.0 MicroEdition-Configuration: CLDC-1.0 MIDlet-1: HelloWorld,, HelloMIDlet <html> <body> <a href="http://<host>/<path>/hello.jad">Hello World<a> </body> </html> Bundling the MIDletCreate a Jar file with all the classes and resources needed by your application.cd classes jar cmf hello.mf hello.jar HelloMIDlet.class MIDlet Installation on a Web ServerPlace the descriptor file, the Jar file, and the OTA listing in a web server visible directory. This will allow your application to be downloadable over the network.The web server must be configured to deliver a specific MIME type for the descriptor and jar files. If using Apache, add the following two lines to the httpd.conf file: AddType text/vnd.sun.j2me.app-descriptor .jad AddType application/java-archive .jar Running the MIDlet from the command lineThe following command demonstrates how to invoke the midp executable with a remote URL. The -transient argument causes the descriptor file to be fetched and the Jar file referenced in the descriptor file to be temporarily installed and started. When the application is destroyed, the temporarily installed application is removed.bin/midp -transient http://<host>/<path>/hello.jad Installing and running the MIDlet using the GUIThe following demonstrates how to invoke the midp executable to emulate how a user will provision and run an application over the air and run it. The presence of no arguments causes the graphical application manager to be displayed. The graphical manager can install, list, launch, update, and remove applications.bin/midp When the MIDP RI GUI pops up: Choose Install. Enter the URL of the hello.html and choose Go. Select "Hello World" from the list and choose Install. When the list of suites is showing select "HelloWorld" from the list and choose Launch. Copyright 2001 Sun Microsystems, Inc., 901 San Antonio Road, Palo Alto, California 94303, U.S.A. All rights reserved. This product is distributed under licenses restricting its use, copying, distribution, and decompilation. No part of this product may be reproduced in any form by any means without prior written authorization of Sun and its licensors, if any. Third-party software, including font technology, is copyrighted and licensed from Sun suppliers. Sun, Sun Microsystems, the Sun Logo, Java, and the Java Coffee Cup Logo are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. Federal Acquisitions: Commercial Software -- Government Users Subject to Standard License Terms and Conditions. DOCUMENTATION IS PROVIDED "AS IS" AND ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD TO BE LEGALLY INVALID.
|