Appendix G. Tool Summary

In this summary, we use a monospaced font for actual commands such as javac. An italic font denotes descriptions of tool command components such as options. Items enclosed in brackets [...] are optional. Items separated by vertical bars | are alternatives. Do not include the brackets or vertical bars when typing the commands.

The Java Compiler

javac [options] sourceFile1|@fileList1 sourceFile2|@fileList2 ...

A file list is a text file that contains one file name per line. For example,

File Greeting.list

1  Greeting.java
2  GreetingTest.java

Then you can compile all files with the command

javac @Greeting.list

The Java compiler options are summarized in Table 1.

Table G.1. Common Compiler Options

Option

Description

-classpath locations

or

-cp locations

The compiler is to look for classes on this path, overriding the CLASSPATH environment variable. If neither is specified, the current directory is used.

Each location is a directory, JAR file, or ZIP file. Locations are separated by a platform-dependent separator (: on Unix, ; on Windows).

-sourcepath locations

The compiler is to look for source files on this path. If not specified, source files are searched in the class path.

-d directory

The compiler places files into the specified directory.

-g

Generate debugging information.

-verbose

Include information about all classes that are being compiled (useful for troubleshooting).

-deprecation

Give detailed information about the usage of deprecated messages.

-Xlint: errorType

Carry out additional error checking. If you get warnings about unchecked conversions, compile with the -Xlint:unchecked option.

The Java Virtual Machine Launcher

The following command loads the given class and starts its main method, passing it an array containing the provided command line arguments.

java [options] ClassName [argument1 argument2 ... ]

The following command loads the main class of the given JAR file and starts its main method, passing it an array containing the provided command line arguments.

java [options] -jar jarFileName [argument1 argument2 ... ]

The Java virtual machine options are summarized in Table 2.

Table G.2. Common Virtual Machine Launcher Options

Option

Description

-classpath locations

or

-cp locations

Look for classes on this path, overriding the CLASSPATH environment variable. If neither is specified, the current directory is used.

Each location is a directory, JAR file, or ZIP file. Locations are separated by a platform-dependent separator (: on Unix, ; on Windows).

-verbose

Trace class loading

-Dproperty=value

Set a system property that you can retrieve with the System.getProperties method.

The Applet Viewer

appletviewer url1 url2 ...

The urls are searched for applets, and each applet is displayed in a separate window. An applet should be specified as an HTML tag of the form

<applet
   code=appletClassFile
   width=pixels
   height=pixels
   [codebase=relativeURL]>
   <param name=parameterName1 value=parameterValue1>
   <param name=parameterName2 value=parameterValue2>
   ...
</applet>

The codebase parameter is an URL that is relative to the URL of the HTML file containing the applet or object tag.

The JAR Tool

To combine one or more files into a JAR (Java Archive) file, use the command

jar cvf jarFile file1 file2 ...

The resulting JAR file can be included in a class path.

To build a program that can be launched with java -jar, you must create a manifest file, such as

File myprog.mf

1 Main-Class: com/horstmann/MyProg

The manifest must specify the path name of the class file that launches the application, but with the .class extension removed. Then build the JAR file as

jar cvfm jarFile manifestFile file1 file2 ...

You can also use JAR as a replacement for a ZIP utility, simply to compress and bundle a set of files for any purpose. Then you may want to suppress the generation of the JAR manifest, with the command

jar cvfM jarFile file1 file2 ...

To extract the contents of a JAR file into the current directory, use

jar xvf jarFile

To see the files contained in a JAR file without extracting the files, use

jar tvf jarFile
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.217.220