'; zhtm += ''; zhtm += '

' + pPage + ''; zhtm += '
'; window.popUpWin.document.write(zhtm); window.popUpWin.document.close(); // Johnny Jackson 4/28/98 } //--> Java 1.2 Unleashed -- Appendix C -- The JDK 1.2 Toolset

Java 1.2 Unleashed


- C -

The JDK 1.2 Toolset

This appendix describes the tools that are provided with JDK 1.2 and summarizes their usage options.

Development Tools

Because the purpose of the JDK is Java software development, most of the JDK tools are development tools. These tools include the Java compiler, bytecode interpreter, debugger, disassembler, documentation generator, and applet viewer. The C-language header file and stub generator tool are also provided.


The javac compiler is used to compile Java source code files (ending with .java) into bytecode files (ending with .class). It is invoked as follows:

javac [options] SourceFileNames

The source file names are a space-separated list of source code files ending with .java. The options are used to control the compiler's operation. They are as follows:


The Java interpreter, java, is used to execute Java bytecode (.class) files. It is invoked in the following ways:

java [options] className [arguments]
java [options] -jar jarFile [arguments]

In the first form, the class name is the name of the class whose main() method is to be executed. The arguments are the program's arguments and are separated by spaces.

In the second form, java executes a program contained in the JAR file. The class to be executed must be specified by the Main-Class manifest header.

The options to the Java interpreter are as follows:

In addition to these options, a number of non-standard options are also used with java. These options are defined in the JDK 1.2 tool documentation.

A special version of java, javaw, creates a separate console window for output.

In most cases, unless you are doing advanced debugging, you will not need any of the specialized versions of java.


The Java debugger, jdb, is used to debug Java programs. It is invoked as follows:

jdb [options] [className]

The jdb options are as follows:

The -host and -password parameters are used to attach the debugger to an interpreter that is currently executing. In addition to the preceding debugger options, a number of options can be forwarded to the process being debugged. These options are covered in the JDK 1.2 documentation.


The Java disassembler, javap, is used to recover Java source code from bytecode files. The disassembler is invoked as follows:

javap [options] className

The following options are supported by javap:

If no options are specified, javap prints the public fields and methods of the class it is disassembling.


The Java documentation generator, javadoc, is used to produce the fine Web pages used to document Java packages. The javadoc tool is invoked as follows:

javadoc [options] targets

The targets are a space-separated list of package names or Java source files for which documentation is to be generated. The javadoc options are as follows:

Appendix D, "Generating Documentation and Help Files," covers the use of javadoc.


The appletviewer is used to view and test applets. It is invoked as follows:

appletviewer [options] url

The URL is the URL of the HTML file containing the applet to be viewed. It can also be the name of a file in the local file system. The options are as follows:

In addition to these options, appletviewer allows the following properties to be set:

These properties are set by selecting Properties from the Applet pulldown menu. Refer to Figure C.1.

FIGURE C.1. Setting the properties of the appletviewer.


The Java header file and stub generator, javah, creates C header files and code stubs for writing native methods. It is invoked as follows:

javah [options] className

The class name is the name of the class for which the header and stub files are to be generated. The options used with javah are as follows:

A special version of javah, javah_g, is non-optimized and more suitable for use in debugging.

Chapter 53, "Native Methods," illustrates the use of the javah tool.

Conversion Tools

The JDK provides a tool, native2ascii, for converting non-Unicode files to Unicode files. This tool converts non-Unicode Latin-1 text files to Unicode Latin-1 files. It is invoked as follows:

native2ascii [options] [inputFile [outputFile]]

The input file is the name of the file to be converted, and the output file is the file to which the converted output is to be written. If the output file is not specified, results are written to the standard output stream. If the input file is not specified, input is taken from the standard input stream. The native2ascii tool supports two options: -reverse and -encoding. The -reverse option is used to reverse the conversion process. Instead of converting from non-Unicode to Unicode, conversion takes place in the other direction. The -encoding option is used to specify the encoding name that is used in the conversion. The JDK 1.2 documentation for native2ascii specifies a number of encoding constants that encompass many of the common international character sets.

Archive Tools

The JDK provides the jar tool to archive a number of files into a single .jar file. The jar tool is covered in Chapter 8, "Applet Security." The jar tool is invoked as follows:

jar [options] [manifestFile] destinationFile inputFiles

The manifest file is used to store information about the archive. If a manifest file is not supplied, jar will automatically create one named META-INF/MANIFEST.INF.

The destination file is the .jar file that is to contain the archive. The input files are a space-separated list of the files that are to be added to the archive. Wildcard characters may be used to specify these files. If one of the input file names is the name of a dir-ectory, the directory is processed recursively, adding all of the files and subdirectories contained in the directory to the archive.

The options used with jar are as follows:

The @ character is used to specify the name of a file containing an additional jar argument. The contents of the file are inserted into the command line (one argument per input file line) at the point where the @ character occurs.

Security Tools

JDK 1.2 provides three tools that are used to implement the Java security policy: policytool, keytool, and jarsigner. These tools are covered in the following subsections.


The policytool is a GUI-based tool that provides a convenient way to edit the security policy of a local JDK installation. This tool is invoked as follows:


The policytool displays the opening window shown in Figure C.2. Select Open from the File menu and then select the policy file that you want to edit. The default policy is jdk1.2\lib\security\java.policy. Use the Add Policy Entry, Edit Policy Entry, and Remove Policy Entry buttons to edit the policy, and select Save from the File menu to save the updated policy.

FIGURE C.2. The policytool opening display.


The keytool is used to manage a local database of keys and certificates. It is invoked as follows:

keytool [commands]

Entering keytool -help provides a list of the keytool commands and their options. These commands and options are described in the JDK 1.2 documentation of the keytool. Chapter 8 covers the use of the keytool.


The jarsigner tool is used to sign a jar file and to verify the signature of a signed jar file. It is invoked as follows:

jarsigner [options] jarFile alias

The jarFile argument identifies the name of the jar file to be signed or verified. The alias argument is the alias of the keystore entry containing the private key used to generate the signature. The keystore is a database of keys and certificates maintained by the keytool.

The options used with jarsigner are as follows:

Chapter 8 covers the use of the jarsigner tool.

Remote Method Invocation Tools

JDK 1.2 provides four remote method invocation (RMI) tools to enable the development and execution of distributed applications. These tools are covered in the following subsections and in Chapter 38, "Building Distributed Applications with the java.rmi Packages," and Chapter 39, "Remote Method Invocation."


The RMI compiler, rmic, is used to generate the skeleton and stub files for an object that is to be accessed using RMI. It is invoked as follows:

rmic [options] classNames

The class names are the fully qualified class names of the classes for which stubs and skeletons are to be generated. The rmic options are as follows:

The GUI version of rmic, generated using the -show option, is shown in Figure C.3.

FIGURE C.3. The GUI-based rmic tool.


The rmiregistry tool is used to start a remote object registry, which makes remote objects available to distributed applications. It is invoked as follows:

start rmiregistry [port]

The port is the TCP port used by the remote object registry. If the port is not specified, the default port of 1099 is used.


The RMI activation system daemon is a server process that supports the activation and registration of objects on a remote system. The rmid tool starts the RMI activation system daemon. It is used as follows:

rmid [-port port] [-log dir]

The port option specifies the TCP port to be used by the daemon. The default port is 1098. The -log option is used to specify the directory that the daemon uses for its database. The default directory is the log subdirectory of the directory in which rmid is invoked.


The serialver tool is used to calculate the serialVersionUID of a class. The serialVersionUID is a unique object identifier used in distributed applications. The serialver tool is invoked as follows:

serialver [-show] [className]

The -show option is used to launch the GUI implementation of serialver. Refer to Figure C.4.

FIGURE C.4. The GUI-based serialver tool.

Java IDL Tools

The tnameserv tool is used to start the Java IDL nameserver on a specified port. The Java IDL nameserver provides a simple implementation of the CORBA Common Object Services (COS) Naming Service. It is invoked as follows:

tnameserv [-ORBInitialPort port]

The optional port specifies the TCP port to be used with the naming service. The default port is 900. Chapter 41, "Java IDL and ORBs," covers the use of tnameserv.

Servlet Tools

The servletrunner is used to run and test servlets. Although servletrunner is no longer part of the JDK 1.2, it is summarized here for your convenience. The servletrunner tool is invoked using the following:

servletrunner [options]

The servletrunner options are used to control the operation of servletrunner. These options are as follows:

Chapter 48, "Programming Other Servers," covers the use of servletrunner.


© Copyright 1998, Macmillan Computer Publishing. All rights reserved.