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.
javac [options
]sourceFile
1|@fileList
1sourceFile
2|@fileList
2 ...
A file list is a text file that contains one file name per line. For example,
File Greeting.list
1
Greeting.java2
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 |
---|---|
| The compiler is to look for classes on this path, overriding the Each location is a directory, JAR file, or ZIP file. Locations are separated by a platform-dependent separator ( |
| The compiler is to look for source files on this path. If not specified, source files are searched in the class path. |
| The compiler places files into the specified directory. |
| Generate debugging information. |
| Include information about all classes that are being compiled (useful for troubleshooting). |
| Give detailed information about the usage of deprecated messages. |
| Carry out additional error checking. If you get warnings about unchecked conversions, compile with the |
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
[argument
1argument
2 ... ]
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
] -jarjarFileName
[argument
1argument
2 ... ]
The Java virtual machine options are summarized in Table 2.
Table G.2. Common Virtual Machine Launcher Options
Option | Description |
---|---|
| Look for classes on this path, overriding the Each location is a directory, JAR file, or ZIP file. Locations are separated by a platform-dependent separator ( |
| Trace class loading |
| Set a system property that you can retrieve with the |
appletviewerurl
1url
2 ...
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.
To combine one or more files into a JAR (Java Archive) file, use the command
jar cvfjarFile file
1file
2 ...
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 cvfmjarFile manifestFile file
1file
2 ...
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 cvfMjarFile file
1file
2 ...
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
3.137.217.220