36
36
. ftr VB CB
37
37
. ftr VBI CBI
38
38
.\}
39
- .TH "JAVA" "1" "2024" "JDK 22-ea " "JDK Commands"
39
+ .TH "JAVA" "1" "2024" "JDK 22" "JDK Commands"
40
40
.hy
41
41
.SH NAME
42
42
.PP
63
63
\f[ V ] java\f[ R ] [\f[I] options \f[ R ] ] \f[ V ] --module\f[ R ]
64
64
\f[I] module \f[ R ] [\f[ V ] /\f[ R ]\f[I] mainclass \f[ R ] ] [\f[I] args \f[ R ] ...]
65
65
.PP
66
- To launch a single source-file program:
66
+ To launch a source-file program:
67
67
.PP
68
68
\f[ V ] java\f[ R ] [\f[I] options \f[ R ] ] \f[I] source-file \f[ R ] [\f[I] args \f[ R ]
69
69
\& ...]
@@ -100,11 +100,10 @@ See \f[B]Standard Options for Java\f[R].
100
100
.RE
101
101
.TP
102
102
\f[I] source-file \f[ R ]
103
- Only used to launch a single source-file program.
103
+ Only used to launch a source-file program.
104
104
Specifies the source file that contains the main class when using
105
105
source-file mode.
106
- See \f[B] Using Source-File Mode to Launch Single-File Source-Code
107
- Programs \f[ R ]
106
+ See \f[B] Using Source-File Mode to Launch Source-Code Programs \f[ R ]
108
107
.TP
109
108
\f[I] args \f[ R ] ...
110
109
Optional: Arguments following \f[I] mainclass \f[ R ] ,
@@ -128,8 +127,8 @@ The method declaration has the following form:
128
127
.PP
129
128
In source-file mode, the \f[ V ] java\f[ R ] command can launch a class
130
129
declared in a source file.
131
- See \f[B] Using Source-File Mode to Launch Single-File Source-Code
132
- Programs \f[ R ] for a description of using the source-file mode.
130
+ See \f[B] Using Source-File Mode to Launch Source-Code Programs \f[ R ] for
131
+ a description of using the source-file mode.
133
132
.RS
134
133
.PP
135
134
\f[B] Note: \f[ R ] You can use the \f[ V ] JDK_JAVA_OPTIONS\f[ R ] launcher
@@ -157,7 +156,7 @@ Use \f[V]javaw\f[R] when you don\[aq]t want a command prompt window to
157
156
appear.
158
157
The \f[ V ] javaw\f[ R ] launcher will, however, display a dialog box with
159
158
error information if a launch fails.
160
- .SH USING SOURCE-FILE MODE TO LAUNCH SINGLE-FILE SOURCE-CODE PROGRAMS
159
+ .SH USING SOURCE-FILE MODE TO LAUNCH SOURCE-CODE PROGRAMS
161
160
.PP
162
161
To launch a class declared in a source file, run the \f[ V ] java\f[ R ]
163
162
launcher in source-file mode.
@@ -205,26 +204,25 @@ Any arguments placed after the name of the source file in the original
205
204
command line are passed to the compiled class when it is executed.
206
205
.PP
207
206
For example, if a file were named \f[ V ] HelloWorld.java\f[ R ] and
208
- contained a class named \f[ V ]hello.World \f[ R ] , then the source-file mode
207
+ contained a class named \f[ V ]HelloWorld \f[ R ] , then the source-file mode
209
208
command to launch the class would be:
210
209
.RS
211
210
.PP
212
211
\f[ V ] java HelloWorld.java\f[ R ]
213
212
.RE
214
213
.PP
215
- The example illustrates that the class can be in a named package, and
216
- does not need to be in the unnamed package.
217
214
This use of source-file mode is informally equivalent to using the
218
- following two commands where \f[ V ] hello.World\f[ R ] is the name of the
219
- class in the package:
215
+ following two commands:
220
216
.IP
221
217
.nf
222
218
\f[CB]
223
- javac -d <memory> HelloWorld.java
224
- java -cp <memory> hello.World
219
+ javac -d <memory> --source-path <source-root> HelloWorld.java
220
+ java --class-path <memory> HelloWorld
225
221
\f[ R ]
226
222
.fi
227
223
.PP
224
+ where \f[ V ] <source-root>\f[ R ] is computed
225
+ .PP
228
226
\f[B] In source-file mode, any additional command-line options are
229
227
processed as follows: \f[ R ]
230
228
.IP \[bu ] 2
@@ -253,9 +251,24 @@ filename with an \f[V]\[at]\f[R] character.
253
251
.IP \[bu ] 2
254
252
Any command-line options that are relevant to the compilation
255
253
environment are taken into account.
256
- .IP \[bu ] 2
257
- No other source files are found and compiled, as if the source path is
258
- set to an empty value.
254
+ These include:
255
+ \f[ V ] --class-path\f[ R ] /\f[ V ] -classpath\f[ R ] /\f[ V ] -cp\f[ R ] ,
256
+ \f[ V ] --module-path\f[ R ] /\f[ V ] -p\f[ R ] , \f[ V ] --add-exports\f[ R ] ,
257
+ \f[ V ] --add-modules\f[ R ] , \f[ V ] --limit-modules\f[ R ] ,
258
+ \f[ V ] --patch-module\f[ R ] , \f[ V ] --upgrade-module-path\f[ R ] ,
259
+ \f[ V ] --enable-preview\f[ R ] .
260
+ .IP \[bu ] 2
261
+ The root of the source tree, \f[ V ] <source-root>\f[ R ] is computed from
262
+ the package of the class being launched.
263
+ For example, if \f[ V ] HelloWorld.java\f[ R ] declared its classes to be in
264
+ the \f[ V ] hello\f[ R ] package, then the file \f[ V ] HelloWorld.java\f[ R ] is
265
+ expected to reside in the directory \f[ V ] somedir/hello/\f[ R ] .
266
+ In this case, \f[ V ] somedir\f[ R ] is computed to be the root of the source
267
+ tree.
268
+ .IP \[bu ] 2
269
+ The root of the source tree serves as the source-path for compilation,
270
+ so that other source files found in that tree and are needed by
271
+ \f[ V ] HelloWorld\f[ R ] could be compiled.
259
272
.IP \[bu ] 2
260
273
Annotation processing is disabled, as if \f[ V ] -proc:none\f[ R ] is in
261
274
effect.
@@ -266,45 +279,54 @@ the compilation.
266
279
This sets both the source version accepted by compiler and the system
267
280
API that may be used by the code in the source file.
268
281
.IP \[bu ] 2
269
- The source file is compiled in the context of an unnamed module.
282
+ If a \f[ V ] module-info.java\f[ R ] file exists in the
283
+ \f[ V ] <source-root>\f[ R ] directory, its module declaration is used to
284
+ define a named module that will contain all the classes compiled from
285
+ \f[ V ] .java\f[ R ] files in the source tree.
286
+ If \f[ V ] module-info.java\f[ R ] does not exist, all the classes compiled
287
+ from source files will be compiled in the context of the unnamed module.
270
288
.IP \[bu ] 2
271
- The source file should contain one or more top-level classes, the first
272
- of which is taken as the class to be executed.
289
+ The source file that is launched should contain one or more top-level
290
+ classes, the first of which is taken as the class to be executed.
273
291
.IP \[bu ] 2
274
- The compiler does not enforce the optional restriction defined at the
275
- end of JLS 7.6, that a type in a named package should exist in a file
276
- whose name is composed from the type name followed by the
277
- \f[ V ] .java\f[ R ] extension.
292
+ For the source file that is launched, the compiler does not enforce the
293
+ optional restriction defined at the end of JLS 7.6, that a type in a
294
+ named package should exist in a file whose name is composed from the
295
+ type name followed by the \f[ V ] .java\f[ R ] extension.
278
296
.IP \[bu ] 2
279
- If the source file contains errors, appropriate error messages are
280
- written to the standard error stream, and the launcher exits with a
281
- non-zero exit code.
297
+ If a source file contains errors, appropriate error messages are written
298
+ to the standard error stream, and the launcher exits with a non-zero
299
+ exit code.
282
300
.PP
283
301
\f[B] In source-file mode, execution proceeds as follows: \f[ R ]
284
302
.IP \[bu ] 2
285
303
The class to be executed is the first top-level class found in the
286
304
source file.
287
- It must contain a declaration of the standard
288
- \f[ V ] public static void main(String[])\f[ R ] method.
305
+ It must contain a declaration of an entry \f[ V ] main\f[ R ] method.
289
306
.IP \[bu ] 2
290
307
The compiled classes are loaded by a custom class loader, that delegates
291
308
to the application class loader.
292
309
This implies that classes appearing on the application class path cannot
293
- refer to any classes declared in the source file.
294
- .IP \[bu ] 2
295
- The compiled classes are executed in the context of an unnamed module,
296
- as though \f[ V ] --add-modules=ALL-DEFAULT\f[ R ] is in effect.
310
+ refer to any classes declared in source files.
311
+ .IP \[bu ] 2
312
+ If a \f[ V ] module-info.java\f[ R ] file exists in the
313
+ \f[ V ] <source-root>\f[ R ] directory, then all the classes compiled from
314
+ \f[ V ] .java\f[ R ] files in the source tree will be in that module, which
315
+ will serve as the root module for the execution of the program.
316
+ If \f[ V ] module-info.java\f[ R ] does not exist, the compiled classes are
317
+ executed in the context of an unnamed module, as though
318
+ \f[ V ] --add-modules=ALL-DEFAULT\f[ R ] is in effect.
297
319
This is in addition to any other \f[ V ] --add-module\f[ R ] options that may
298
320
be have been specified on the command line.
299
321
.IP \[bu ] 2
300
322
Any arguments appearing after the name of the file on the command line
301
- are passed to the standard main method in the obvious way.
323
+ are passed to the main method in the obvious way.
302
324
.IP \[bu ] 2
303
325
It is an error if there is a class on the application class path whose
304
326
name is the same as that of the class to be executed.
305
327
.PP
306
- See \f[B] JEP 330 : Launch Single -File Source-Code Programs \f[ R ]
307
- [https://openjdk.org/jeps/330 ] for complete details.
328
+ See \f[B] JEP 458 : Launch Multi -File Source-Code Programs \f[ R ]
329
+ [https://openjdk.org/jeps/458 ] for complete details.
308
330
.SH USING THE JDK_JAVA_OPTIONS LAUNCHER ENVIRONMENT VARIABLE
309
331
.PP
310
332
\f[ V ] JDK_JAVA_OPTIONS\f[ R ] prepends its content to the options parsed
0 commit comments