java

Name

java -- launch a Java application

Synopsis

java [-?] [-Dproperty=value] [-classpath] [-cp] [-help] [-jar file.jar] [-version] [arguments...]

Description

The java command shall launch a Java application by initializing a Java runtime environment, loading the class specified on the command line, and calling the main method of that class.

The method's declaration must be as follows.

public static void main(String args[])

By default, the first argument specified that is not an option shall be the fully-qualified name of the class to invoke. This behavior may be changed by the addition of the -jar option, in which case the first argument specified that is not an option shall be the name of a JAR file. Any arguments specified after the class name or JAR file name that are not command-line options are passed to the main function.

The Java runtime shall search for the classes used, including the startup class, in three locations: the bootstrap class path, the extensions that are currently installed, and the user class path.

Options

-? 

This option is a synonym for -help.

-classpath classpath 

This option shall specify a list of locations to search for class files, including directories, JAR files, and ZIP files. Locations in the class path shall be delimited by colons (:).

The -classpath option shall override the CLASSPATH environment variable. If the -classpath option is not specified and CLASSPATH is not set, then the user class path shall simply consist of the current directory (.).

The class path element * shall specify all files in the current directory with the extension .jar. or .JAR. Example: if the only JAR files in the directory foo are bar.jar and bas.JAR, then the class path element foo/* shall be equivalent to bar.jar:bas.JAR. The order of JAR files in this case shall be unspecified. The CLASSPATH environment variable functions in the same way.

Wildcards in the class path shall be expanded before the initialization of the Java virtual machine. However, Java programs can examine unexpanded wildcards if they query the environment. Example: System.getenv("CLASSPATH").

-cp classpath 

This option is a synonym for -classpath.

-Dproperty=value 

This option shall set the value of a system property.

-help 

This option shall display usage information for the command, then exit.

-jar jarfile 

This option shall specify a JAR file containing a program to execute. Its first argument must be the name of a JAR file with both class and resource files. The JAR file's manifest must contain a line of this form: Main-Class: classname. The class name classname must specify the class containing the main function for the application.

If this option is specified, all other user class path settings shall be ignored.

JAR files that can be specified with this option shall also be runnable without this option by setting their execute permissions.

-version 

This option shall display version information for the command, then exit.