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).
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.
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:
The Default Device Selection dialog appears with a menu of devices.
The next time you run a MIDlet, it will be emulated on the device you have chosen.
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:
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:
-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.
wscompile -gen -d generated config.xml wscompile -gen -f:nounwrap -O -cldc1.1 -d generated config.xml
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:
tmpclasses
. A directory to hold unverified classes.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.
<files>
A list of one or more source files to compile, separated by spaces.
-d
<output directory>
Specify the directory into which the compiler should output classes. (This directory must exist before compiling.)
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.
To preverify application classes, use the preverify command that comes with the J2ME Wireless Toolkit. The syntax for the preverify command is as follows:
You can find the preverify application in the {j2mewtk.dir}\bin
directory.
<files | directories>
A list of one or more files or directories to preverify, separated by spaces.
-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:
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.
To package a MIDlet suite, you must first create a manifest file, then create an application JAR file, and finally, an application JAD 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
Create a JAR file containing the manifest as well as the suite’s class and resource files.
<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.
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:
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
.
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
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):
-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.
-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.
-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).
-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:
-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.
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.
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:
-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
.
_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.
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.
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:
-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:
-encoding
is UTF-8
-jarfile
is the MIDlet-Jar-URL
property in the JAD-keystore
is $HOME/.keystore
-certnum
is 1-chainnum
is 1
User's Guide Java™ 2 Platform, Micro Edition, Wireless Toolkit, Version 2.1 |
Copyright © 2003 Sun Microsystems, Inc. All rights reserved.