Contents Previous Next Index

Appendix   D

Command Line Utilities


This appendix describes how to operate the J2ME Wireless Toolkit tools from the command line and details the steps required to build and run an application. It also describes the J2ME Wireless Toolkit’s certificate manager utility, called MEKeyTool (Mobile Equipment KeyTool) and the MIDlet signing utility, called JAD Tool (Java Application Descriptor Tool).

Preliminary Checks

Before building and running an application from the command line, verify that you have a version no earlier than 1.4.2 of the J2SE SDK. Run the jar.exe command (make sure the command is in your PATH) and then run java -version at the command line to verify that the version of the J2SE SDK that is actually being used is 1.4.2.

For more examples, see the files build.bat and run.bat in the bin\ directories of the demonstration applications. You can find these files under the
{j2mewtk.dir}\apps\{demo_name}\bin\ directory where {j2mewtk.dir} is the installation directory of the J2ME Wireless Toolkit and {demo_name} is the name of one of the demo applications.

Selecting a Default Device

If you do not specify which device to emulate, the Emulator uses the default device, DefaultColorPhone, when you run a MIDlet.

To change the default emulated device:

  1. From the Windows Start menu, select Programs -> J2ME Wireless Toolkit 2.1 -> Default Device Selection.
  2. The Default Device Selection dialog appears with a menu of devices.

  3. Select the device from the menu, and press OK.
  4. The next time you run a MIDlet, it will be emulated on the device you have chosen.

Accessing Preferences and Utilities

To access the Preferences and Utilities tools described in Chapter 5, "Working With the Emulator” and Chapter 4, "Performance Tuning and Monitoring Applications” from the command line, type the following commands at the prompt:


{j2mewtk.dir}\bin\prefs.exe 

{j2mewtk.dir}\bin\utils.exe 

Using the Stub Generator

J2ME Clients can use the Stub Generator to access web services. The wscompile tool generates stubs, ties, serializers, and WSDL files used in 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  

Options

TABLE 7  –  Options for the wscompile Command
Option
Description
-d <output directory>
specify where to place generated output files
-f:<features>
enable the given features
-features:<features>
same as -f:<features>
-g
generate debugging info
-gen
same as -gen:client
-gen:client
generate client artifacts (stubs, etc.)
-httpproxy:<host>:<port>
specify a HTTP proxy server (port defaults to 8080)
-import
generate interfaces and value types only
-model <file>
write the internal model to the given file
-O
optimize generated code
-s <directory>
specify where to place generated source files
-verbose
output messages about what the compiler is doing
-version
print version information
-cldc1.0
Set the CLDC version to 1.0 (default) (float and double become String)
-cldc1.1
Set the CLDC version to 1.1 (float and double are ok)
-cldc1.0info
Show all CLDC 1.0 info/warning messages.


Note – Exactly one -gen option must be specified. The -f option requires a comma-separated list of features.

TABLE 8 lists the features (delimited by commas) that may 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.

TABLE 8  –  Command Supported Features (-f) for wscompile
Option
Description
Type of File
explicitcontext
turn on explicit service context mapping
WSDL
nodatabinding
turn off data binding for literal encoding
WSDL
noencodedtypes
turn off encoding type information
WSDL, SEI, model
nomultirefs
turn off support for multiple references
WSDL, SEI, model
novalidation
turn off full validation of imported WSDL documents
WSDL
searchschema
search schema aggressively for subtypes
WSDL
serializeinterfaces
turn on direct serialization of interface types
WSDL, SEI, model
wsi
enable WSI-Basic Profile features (default)
 
resolveidref
Resolve xsd:IDREF
 
nounwrap
No unwrap.
 


wscompile -gen -d generated config.xml 

wscompile -gen -f:nounwrap -O -cldc1.1 -d generated config.xml 

Compiling Class Files

J2ME class files are compiled from Java source files using the javac compiler from the J2SE SDK. Before compiling, you should verify that the following subdirectories exist and create them if necessary:

  1. tmpclasses. A directory to hold unverified classes.
  2. classes. A directory to hold verified classes.

To compile an application, use the javac command as follows (all on one line):


javac [options] -bootclasspath {j2mewtk.dir}\lib\cldcapi10.jar;{j2mewtk.dir}\lib\midpapi20.jar <files> 

If your application uses WMA, J2ME Web Services, MMAPI, or other versions of CLDC or MIDP, be sure to include the relevant .jar files in the bootclasspath.

Arguments

<files>

A list of one or more source files to compile, separated by spaces.

Options

-d <output directory>

Specify the directory into which the compiler should output classes. (This directory must exist before compiling.)

Example

To compile all the source files of a CLDC 1.0, MIDP 2.0 MIDlet located in the src directory (but not its subdirectories) and place the resulting class files into the directory tmpclasses, use the following command:


javac -d tmpclasses -bootclasspath c:\wtk21\lib\cldcapi10.jar;c:\wtk21\lib\midpapi20.jar -classpath tmpclasses;classes src\*.java 

The tmpclasses directory is used to store the compiled classes while they are not yet verified. After verification has been performed, the preverifier stores the classes in the classes directory. For more information about the javac command, see the J2SE SDK documentation.

Preverifying Classes

To preverify application classes, use the preverify command that comes with the J2ME Wireless Toolkit. The syntax for the preverify command is as follows:


preverify [options] <files | directories> 

You can find the preverify application in the {j2mewtk.dir}\bin directory.

Arguments

<files | directories>

A list of one or more files or directories to preverify, separated by spaces.

Options

-classpath <classpath>

Specify the directories or JAR files (given as a semicolon-delimited list) from which classes are loaded.

-d <output directory>

Specify the directory into which the preverifier should 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 in the previous section, after compiling the source files, use the following command:


preverify -classpath c:\wtk21\lib\cldcapi10.jar;c:\wtk21\lib\midpapi20.jar -d classes tmpclasses  

As a result of this command, pre-verified versions of the class files are placed in the classes directory. If your application uses WMA, J2ME Web Services, MMAPI, or other versions of CLDC or MIDP, be sure to include the relevant .jar files in the classpath.

Packaging a MIDlet Suite

To package a MIDlet suite, you must first create a manifest file, then create an application JAR file, and finally, an application JAD file.

Creating a Manifest File

Create a manifest file containing the appropriate attributes as specified in Appendix A, "MIDlet Attributes.”

You can use any plain 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 

Creating an Application JAR File

Create a JAR file containing the manifest as well as the suite’s class and resource files.

Arguments

<file>

The JAR file to create.

<manifest>

The manifest file for the MIDlets.

<class_directory>

The directory containing the application’s classes.

<resource_directory>

The directory containing the application’s resources.

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 . 

Creating an Application JAD File

Create a JAD file containing the appropriate attributes as specified in Appendix A, "MIDlet Attributes.” You can use any plain 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.

Example

A JAD file might have the following contents, for example:


MIDlet-Name: MyMIDlet 

MIDlet-Vendor: My Organization 

MIDlet-Version: 1.0 

MIDlet-Jar-URL: MyApp.jar 

MIDlet-Jar-Size: 24601 

Running the Emulator

You can run the Emulator from the command line using the emulator command. Your current directory should be the bin\ subdirectory of the directory where you installed the Wireless Toolkit, for example, C:\wtk21\bin. The syntax for the emulator command is as follows (all on one line):


emulator [options] 

General Options

-help

Display a list of valid options.

-version

Display version information about the emulator.

-Xquery

Print device information on the standard output stream and exit immediately. The information includes, but is not limited to, device name, device screen size, and other device capabilities.

Running Options

-Xdevice:<device_name>

Run an application on the device specified by the given device name. (For a list of device names, see TABLE 3 in Chapter 5, "Working With the Emulator.”

-Xdescriptor:<jad_file>

Run an application locally using the given JAD file.

-classpath <classpath>

Specify the classpath for libraries required to run the application. Use this option when running an application locally.

-D <runtime_property>

Set the HTTP and HTTPS proxy servers. Valid properties include:

com.sun.midp.io.http.proxy=<proxy host>:<proxy port>

-Xjam:<command>=<application>

Run an application remotely using the Application Management System (AMS) to run using OTA provisioning. If no application is specified with the argument, the graphical AMS is run.

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.

transient=<jad_file_url>]

Install, run, and remove the application with the specified JAD file. Specifying transient causes the application to be installed and run and then removed three times.

Tracing and Debugging Options

-Xverbose:<trace_options>

Display trace output, as specified by a list of comma-separated options:

class

Trace class loading.

gc

Trace garbage collection.

all

Use all tracing options.

-Xdebug

Enable runtime debugging. The -Xrunjdwp option must also be used.

-Xrunjdwp:<debug_settings>

Start a JDWP debug session, as specified by a list of comma-separated debug settings. The -Xdebug option must also be used. Valid debug settings include:

transport=<transport_mechanism>

The transport mechanism used to communicate with the debugger. The only transport mechanism supported is dt_socket.

address=<host:port>

The transport address for the debugger connection. You can omit providing a host. If host is omitted, localhost is assumed to be the host machine.

server=y|n

Start the debug agent as a server. The debugger must connect to the port specified. The possible values are y and n. Currently, only y is supported (the Emulator must act as a server).

Emulator Preferences Setting Option

-Xprefs:<filename>

Set the Emulator preferences to the values in the given property file. The filename you provide should be the full path name of a property file, which is used to override the values in the Preferences dialog box. The property file can contain the following properties:

TABLE 9  –  Emulator Preferences Properties List
Property Name
Property Description and Legal Values
http.version
Network Configuration > HTTP Version
Value: HTTP/1.1 | HTTP/1.0
http.proxyHost
Network Configuration > HTTP Address
Value: hostname
http.proxyPort
Network Configuration > HTTP Port
Value: integer
https.proxyHost
Network Configuration > HTTPS Address
Value: hostname
https.proxyPort
Network Configuration > HTTPS Port
Value: integer
kvem.memory.monitor.enable
Monitor > Enable memory monitor
Value: true | false
kvem.netmon.comm.enable
Monitor > Enable Comm monitoring
Value: true | false
kvem.netmon.datagram.enable
Monitor > Enable Datagram monitoring
Value: true | false
kvem.netmon.http.enable
Monitor > Enable HTTP monitoring
Value: true | false
kvem.netmon.https.enable
Monitor > Enable HTTPS monitoring
Value: true | false
kvem.netmon.socket.enable
Monitor > Enable Socket monitoring
Value: true | false
kvem.netmon.ssl.enable
Monitor > Enable SSL monitoring
Value: true | false
kvem.profiler.enable
Monitor > Enable profiling
Value: true | false
netspeed.bitpersecond
Performance > bits/sec combo box
Value: integer
netspeed.enableSpeedEmulation
Performance > Enable network throughput emulation
Value: true | false
screen.graphicsLatency
Performance > Graphics primitives latency
Value: integer
screen.refresh.mode
Performance > Display refresh (radio button)
Value: default | immediate | periodic
screen.refresh.rate
Performance > Display refresh (slider)
Value: integer
vmspeed.bytecodespermilli
Performance > Enable VM speed emulation (check box)
Value: integer
vmspeed.enableEmulation
Performance > Enable VM speed emulation (slider)
Value: true | false
storage.root
Storage > Storage root directory
Value: String (relative path to appdb)
storage.size
Storage > Storage size
Value: integer
mm.control.capture
MMedia > Audio Capture
Value: true | false
mm.control.midi
MMedia > MIDI tones
Value: true | false
mm.control.mixing
MMedia > Audio Mixing
Value: true | false
mm.control.record
MMedia > Audio Record
Value: true | false
mm.control.volume
Value: true | false
mm.format.midi
MMedia > MIDI format
Value: true | false
mm.format.video
MMedia > Video format
Value: true | false
mm.format.wav
MMedia > WAV Audio format
Value: true | false
wma.client.phoneNumber
WMA > Phone Number of Next Emulator
Value: integer
wma.smsc.phoneNumber
WMA > SMS Phone Number
Value: integer
wma.server.firstAssignedPhoneNumber
WMA > First Assigned Phone Number
Value: integer
wma.server.percentFragmentLoss
WMA > % Random Message Fragment Loss
Value: integer
wma.server.deliveryDelayMS
WMA > Message Fragment Delivery Delay (ms)
Value: integer

Emulator Domain Setting Option

-Xdomain <domain_type>

Assigns a security domain to the MIDlet suite. Domain types include:

untrusted

Requires that the MIDlet suite obtain user permission for push functionality and the network protocols: HTTP, HTTPS, socket, datagram, server socket, comm, SMS, and CBS.

trusted

Allows access to the push functionality and all the following network protocols: HTTP, HTTPS, socket, datagram, server socket, comm, SMS, and CBS.

minimum

Denies the MIDlet suite access to all security sensitive APIs. This domain contains no permissions.

maximum

Same as trusted.

Certificate Manager Utility

The MEKeyTool manages the public keys of certificate authorities (CAs), making it functionally similar to the keytool utility that comes with the Java 2 SDK, Standard Edition. 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 (JCE) keystore. You can create one using the J2SE keytool utility, see http://java.sun.com/j2se/1.4/docs/tooldocs/win32/keytool.html for more information.

Usage

The MEKeyTool utility is packaged in a JAR file. To run it, open a command prompt, change the current directory to {j2mewtk.dir}\bin, and enter the following command:


java –jar MEKeyTool.jar <command> 

Commands

-help

Print the usage instructions for MEKeyTool.

-delete [-MEkeystore <MEkeystore>] -owner <owner>

Delete a key from the given ME keystore with the given owner. The default ME keystore is {j2mewtk.dir}\appdb\_main.ks.

-import -alias <alias> [-MEkeystore <MEkeystore>] [-keystore <JCEkeystore>] [-storepass <storepass>] -domain <domain_name>

Import a public key into the given ME keystore from the given JCE keystore using the given JCE keystore password. The default ME keystore is {j2mewtk.dir}\appdb\_main.ks and the default JCE keystore is {user.home}\.keystore.

-list [-MEkeystore <MEkeystore>]

List the keys in the given ME keystore, including the owner and validity period for each. The default ME keystore is {j2mewtk.dir}\appdb\_main.ks.


Note – The J2ME Wireless Toolkit contains a default ME keystore called _main.ks, which is located in the appdb\ subdirectory. This keystore includes all the certificates that exist in the default J2SE keystore, which comes with the J2SE JDKTM installation.

MIDlet Suite Signing Utility

The 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.

The JADTool only uses certificates and keys from J2SE keystores. The J2SE provides the command-line tool to manage J2SE keystores.

Usage

The JADTool utility is packaged in a JAR file. To run it, open a command prompt, change the current directory to {j2mewtk.dir}\bin, and enter the following command:


java –jar JADTool.jar <command> 

Commands

-help

Print the usage instructions for JADTool.

-addcert -keystore <keystore> -alias <alias> -storepass <password>
[-certnum <number>] [-chainnum <number>] -inputjad <input_jadfile> -outputjad <output_jadfile>

Add the certificate of the key pair from the given keystore to the JAD file. The default ME keystore is {j2mewtk.dir}\appdb\_main.ks.

-addjarsig -jarfile <jarfile> -keystore <keystore> -alias <alias> -storepass <password> -keypass <password> -inputjad <input_jadfile> -outputjad <output_jadfile>

Add 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. The default ME keystore is {j2mewtk.dir}\appdb\_main.ks.

-showcert [([-certnum <number>] [-chainnum <number>]) |-all [-encoding <encoding>] -inputjad <filename>

Display the list of certificates in the given JAD file.

The default value for:

 


Contents Previous Next Index User's Guide
Java™ 2 Platform, Micro Edition, Wireless Toolkit, Version 2.1