|A P P E N D I X B|
Command Line Reference
This appendix describes how to operate the Sun JavaTM Wireless Toolkit for CLDC from the command line and details the steps required to build and run an application. It also describes the Sun JavaTM Wireless Toolkit for CLDC certificate manager utility, called MEKeyTool, and the MIDlet signing utility, called JadTool (Java Application Descriptor Tool).
Before building and running an application from the command line, verify that you have a version no earlier than 1.4.2 of the Java SE software development kit. Make sure the jar command is in your path. To find the version of the development kit, run the jar command and then run java -version at the command line.
For more examples, see the files build.bat and run.bat in the bin directories of the demonstration applications. You can find these files in:
toolkit is the installation directory of the Sun JavaTM Wireless Toolkit for CLDC and demo is the name of one of the demo applications.
For a full description of developing MIDP applications, see Chapter 2. This section describes how to accomplish each of the steps in the development cycle from the command line.
In the user interface, building a project is a single step. Behind the scenes, however, there are actually two steps. First, Java source files are compiled into Java class files. Next, the class files are preverified, which means they are prepared for the CLDC KVM.
Use the javac compiler from the Java SE development kit to compile Java source files. You can use the existing Sun JavaTM Wireless Toolkit for CLDC project directory structure. You'll need to use the -bootclasspath option to tell the compiler to use the MIDP APIs, and you'll use the -d option to tell the compiler where to put the compiled class files.
The following example shows how you could compile a MIDP 2.0 application, taking source files from the src directory and placing the class files in the tmpclasses directory. Newlines have been added for clarity.
javac -bootclasspath ..\..\lib\cldcapi10.jar;..\..\lib\midpapi20.jar -d tmpclasses src\*.java
javac -bootclasspath ../../lib/cldcapi10.jar;../../lib/midpapi20.jar -d tmpclasses src/*.java
If you want to use the optional APIs that are supported by the toolkit, add their JAR files to the -bootclasspath option.
For more information on javac, consult the Java SE documentation.
The next step is to preverify the class files. In the bin directory of the Sun JavaTM Wireless Toolkit for CLDC lives a handy utility called preverify. The syntax for the preverify command is as follows:
preverify [options] files | directories
Some of the options are as follows:
Specify the directories or JAR files (given as a semicolon-delimited list) from which classes are loaded.
Specify the target directory for the output classes. This directory must exist before preverifying. If this option is not used, the preverifier places the classes in a directory called output.
Following the example for compiling, use the following command to verify the compiled class files. As before, newlines are added for clarity.
preverify -classpath ..\..\lib\cldcapi10.jar;..\..\lib\midpapi20.jar -d classes tmpclasses
preverify -classpath ../../lib/cldcapi10.jar;../../lib/midpapi20.jar -d classes tmpclasses
As a result of this command, preverified class files are placed in the classes directory. If your application uses WMA, MMAPI, or other versions of CLDC or MIDP, be sure to include the relevant .jar files in the classpath.
To package a MIDlet suite, you must create a manifest file, an application JAR file, and finally, a MIDlet suite descriptor.
Create a manifest file containing the appropriate attributes as specified in the MIDP specification. You can use any text editor to create the manifest file. A manifest might have the following contents, for example:
MIDlet-1: My MIDlet, MyMIDlet.png, MyMIDlet MIDlet-Name: MyMIDlet MIDlet-Vendor: My Organization MIDlet-Version: 1.0 MicroEdition-Configuration: CLDC-1.0 MicroEdition-Profile: MIDP-2.0
Create a JAR file containing the manifest as well as the suite's class and resource files. To create the JAR file, use the jar tool that comes with the Java SE software development kit. The syntax is as follows:
jar cfm file manifest -C class-directory . -C resource-directory .
The arguments are as follows:
For example, to create a JAR file named MyApp.jar whose classes are in the classes directory and resources are in the res directory, use the following command:
jar cfm MyApp.jar MANIFEST.MF -C classes . -C res .
Create a JAD file containing the appropriate attributes as specified in the MIDP specification. You can use any text editor to create the JAD file. This file must have the extension .jad.
|Note - You need to set the MIDlet-Jar-Size entry to the size of the JAR file created in the previous step.|
For example, a JAD file might have the following contents:
MIDlet-Name: MyMIDlet MIDlet-Vendor: My Organization MIDlet-Version: 1.0 MIDlet-Jar-URL: MyApp.jar MIDlet-Jar-Size: 24601
You can run the emulator from the command line. The Sun JavaTM Wireless Toolkit for CLDC's bin directory contains the command emulator. The syntax for the emulator command is as follows:
The general options are as follows:
Options that pertain to running MIDlet suites are as follows:
A sample call might look like:
emulator -Dcom.sun.midp.midlet.platformRequestCommand=firefox -Xjam:install=URL-to-app-using-platformRequest-method
If you want to use the same browser every time, you can add the following line to toolkit/lib/system.config:
Windows: In Windows, if this parameter is not specified, the default browser is used.
Linux: For Linux, this parameter is required because Linux systems do not usually have a default browser. If it is missing, nothing happens when an application tries to open a URL.
install=jad-file-url | force | list | storageNames|
Install the application with the specified JAD file onto a device.
run=[storage-name | storage-number]
Run a previously installed application. The application is specified by its valid storage name or storage number.
remove=[storage-name | storage-number | all]
Remove a previously installed application. The application is specified by its valid storage name or storage number. Specifying all, all previously installed applications are removed.
You can use the following options with the emulator for debugging and tracing.
The components of the Sun JavaTM Wireless Toolkit for CLDC can all be launched from the command line. Each component is in the toolkit's bin directory.
You can change the emulator preferences from the command line by using the -Xprefs option for the emulator command. The format is as follows:
Provide a filename that is the full path name of a property file whose values override the values in the preferences dialog box. The property file can contain the properties described in the following table.
The full spectrum of the Sun JavaTM Wireless Toolkit for CLDC's security features are also available from the command line. You can adjust the emulator's default protection domain, sign MIDlet suites, and manage certificates.
To adjust the emulator's default protection domain, use the following option with the emulator command:
Assigns a security domain to the MIDlet suite. Domain types include untrusted, trusted, minimum, and maximum.
JadTool is a command-line interface for signing MIDlet suites using public key cryptography according to the MIDP 2.0 specification. Signing a MIDlet suite is the process of adding the signer certificates and the digital signature of the JAR file to a JAD file. JadTool is also capable of signing payment update (JPP) files.
JadTool only uses certificates and keys from Java SE platform keystores. Java SE software provides keytool, the command-line tool to manage Java SE platform keystores.
JadTool is packaged in a JAR file. To run it, open a command prompt, change the current directory to toolkit\bin, and enter the following command:
java -jar JadTool.jar command
The commands are as follows:
Prints the usage instructions for JADTool.
Adds the certificate of the key pair from the given keystore to the JAD file or JPP file.
Adds the digital signature of the given JAR file to the specified JAD file. The default value for -jarfile is the MIDlet-Jar-URL property in the JAD file.
Displays the list of certificates in the given JAD file.
Adds a digital signature of the input JPP file to the specified output JPP file.
The default value are as follows:
MEKeyTool manages the public keys of certificate authorities (CAs), making it functionally similar to the keytool utility that comes with the Java SE SDK. The keys can be used to facilitate secure HTTP communication over SSL (HTTPS).
Before using MEKeyTool, you must first have access to a Java Cryptography Extension keystore. You can create one using the Java SE keytool utility.
To run MEKeyTool, open a command prompt, change the current directory to toolkit\bin, and enter the following command:
The command keywords follow. Note that while MEKeyTool runs from the installation directory, the default keys and keys you create will reside in your personal directory, workdir\appdb.
Prints the usage instructions for MEKeyTool.
Imports a public key into the ME keystore from the given JCE keystore using the given Java Cryptography Extension keystore password. The default ME keystore is workdir\appdb\_main.mks and the default Java Cryptography Extension keystore is user.home\.keystore.
Lists the keys in the ME keystore, including the owner and validity period for each. The ME keystore is workdir\appdb\_main.mks.
Deletes a key from the given ME keystore with the given owner. The ME keystore is workdir\appdb\_main.mks.
|Note - The Sun JavaTM Wireless Toolkit for CLDC contains an ME keystore called _main.mks, which is located in the appdb subdirectory. This keystore includes all the certificates that exist in the default Java SE platform keystore, which comes with the Java SE SDK installation.|
Mobile clients can use the Stub Generator to access web services. The wscompile tool generates stubs, ties, serializers, and WSDL files used in Java API for XML (JAX) RPC clients and services. The tool reads a configuration file, which specifies either a WSDL file, a model file, or a compiled service endpoint interface. The syntax for the stub generator command is as follows:
wscompile [options] configuration-files
|Note - Exactly one -gen option must be specified. The -f option requires a comma-separated list of features.|
TABLE B-4 lists the features (delimited by commas) that can follow the -f option. The wscompile tool reads a WSDL file, compiled service endpoint interface (SEI), or model file as input. The Type of File column indicates which of these files can be used with a particular feature.
wscompile -gen -d generated config.xml wscompile -gen -f:nounwrap -O -cldc1.1 -d generated config.xml