如何在启动时将 JVM 选项传递给 jshell
How to pass JVM options to jshell while starting it
我想执行以下操作:
jshell -v -Duser.country=FR -Duser.language=fr
以便获得例如个性化 Locale.getDefault()
。
一种可能的方法是使用 startup script 例如setLocale.jsh
脚本的内容是:
java.util.Locale.setDefault(java.util.Locale.CANADA) // set your locale
然后您可以在 jshell
命令行上使用
/set start <path to setLocale.jst>
并确保重置状态以应用更改
/reset
要验证 Locale
中的更改,您可以
java.util.Locale.getDefault() // prints en_CA
请注意,以上仅暗示到 jshell
的现在 session。可以使用 -retain
选项保留设置,因此如果您使用
/set start -retain
然后设置的启动脚本也将在您下次调用 jshell
工具时加载。
$ jshell -R -Dtest1=one
| Welcome to JShell -- Version 11.0.1
| For an introduction type: /help intro
jshell> System.getProperty("test1")
==> "one"
帮助选项中有记载
$ jshell -h
Usage: jshell <option>... <load-file>...
where possible options include:
--class-path <path> Specify where to find user class files
--module-path <path> Specify where to find application modules
--add-modules <module>(,<module>)*
Specify modules to resolve, or all modules on the
module path if <module> is ALL-MODULE-PATHs
--enable-preview Allow code to depend on preview features of this release
--startup <file> One run replacement for the startup definitions
--no-startup Do not run the startup definitions
--feedback <mode> Specify the initial feedback mode. The mode may be
predefined (silent, concise, normal, or verbose) or
previously user-defined
-q Quiet feedback. Same as: --feedback concise
-s Really quiet feedback. Same as: --feedback silent
-v Verbose feedback. Same as: --feedback verbose
-J<flag> Pass <flag> directly to the runtime system.
Use one -J for each runtime flag or flag argument
-R<flag> Pass <flag> to the remote runtime system.
Use one -R for each remote flag or flag argument
-C<flag> Pass <flag> to the compiler.
Use one -C for each compiler flag or flag argument
--version Print version information and exit
--show-version Print version information and continue
--help, -?, -h Print this synopsis of standard options and exit
--help-extra, -X Print help on non-standard options and exit
我想执行以下操作:
jshell -v -Duser.country=FR -Duser.language=fr
以便获得例如个性化 Locale.getDefault()
。
一种可能的方法是使用 startup script 例如setLocale.jsh
脚本的内容是:
java.util.Locale.setDefault(java.util.Locale.CANADA) // set your locale
然后您可以在 jshell
命令行上使用
/set start <path to setLocale.jst>
并确保重置状态以应用更改
/reset
要验证 Locale
中的更改,您可以
java.util.Locale.getDefault() // prints en_CA
请注意,以上仅暗示到 jshell
的现在 session。可以使用 -retain
选项保留设置,因此如果您使用
/set start -retain
然后设置的启动脚本也将在您下次调用 jshell
工具时加载。
$ jshell -R -Dtest1=one
| Welcome to JShell -- Version 11.0.1
| For an introduction type: /help intro
jshell> System.getProperty("test1")
==> "one"
帮助选项中有记载
$ jshell -h
Usage: jshell <option>... <load-file>...
where possible options include:
--class-path <path> Specify where to find user class files
--module-path <path> Specify where to find application modules
--add-modules <module>(,<module>)*
Specify modules to resolve, or all modules on the
module path if <module> is ALL-MODULE-PATHs
--enable-preview Allow code to depend on preview features of this release
--startup <file> One run replacement for the startup definitions
--no-startup Do not run the startup definitions
--feedback <mode> Specify the initial feedback mode. The mode may be
predefined (silent, concise, normal, or verbose) or
previously user-defined
-q Quiet feedback. Same as: --feedback concise
-s Really quiet feedback. Same as: --feedback silent
-v Verbose feedback. Same as: --feedback verbose
-J<flag> Pass <flag> directly to the runtime system.
Use one -J for each runtime flag or flag argument
-R<flag> Pass <flag> to the remote runtime system.
Use one -R for each remote flag or flag argument
-C<flag> Pass <flag> to the compiler.
Use one -C for each compiler flag or flag argument
--version Print version information and exit
--show-version Print version information and continue
--help, -?, -h Print this synopsis of standard options and exit
--help-extra, -X Print help on non-standard options and exit