upgrade-module-path, and any variant forms of those This includes: -class-path, -module-path,
The launcher scans the options specified before the source file for any that are relevant in order to compile the source file. In source-file mode, any additional command-line options are processed as follows: This use of source-file mode is informally equivalent to using the following two commands where hello.World is the name of the class in the package: The example illustrates that the class can be in a named package, and does not need to be in the unnamed package. Any arguments placed after the name of the source file in the original command line are passed to the compiled class when it is executed.įor example, if a file were named HelloWorld.java and contained a class named hello.World, then the source-file mode command to launch the class would be: In source-file mode, the effect is as though the source file is compiled into memory, and the first class found in the source file is executed. The -source option is used for cases when the source file is a "script" to be executed and the name of the source file does not follow the normal naming conventions for Java source files. java extension, the -source option must be used to tell the java command to use the source-file mode. Supported values of N for this release are 6, 7, 8, 9, 10, and 11. You'll get an error message if you use a value of N that is no longer supported. The valid values of N change for each release, with new values added and old values removed. Optional: Arguments following mainclass, source-file, -jar jarfile, and -m or -module module/ mainclass are passed as arguments to the main class. See Using Source-File Mode to Launch Single-File Source-Code Programs Specifies the source file that contains the main class when using source-file mode. Only used to launch a single source-file program. In other words, mainclass can be used when it is not specified by the module, or to override the value when it is specified. If you’re using JAR files, then see jar.Įxecutes the main class in a module specified by mainclass if it is given, or, if it is not given, the value in the module. When you use -jar, the specified JAR file is the source of all user classes, and other class path settings are ignored. The jarfile argument is the name of a JAR file with a manifest that contains a line in the form Main-Class: classname that defines the class with the public static void main(String args) method that serves as your application's starting point. Command-line entries following classname are the arguments for the main method.Įxecutes a program encapsulated in a JAR file.
Specifies the name of the class to be launched. See Overview of Java Options for a description of available options. Optional: Specifies command-line options separated by spaces. To launch a single source-file program: java source-file To launch the main class in a module: java -m module To launch the main class in a JAR file: java -jar jarfile The javaw launcher will, however, display a dialog box with error information if a launch fails. Use javaw when you don’t want a command prompt window to appear. Windows: The javaw command is identical to java, except that with javaw there’s no associated console window.