启动时如何将JVM选项传递给jshell

时间:2018-12-21 23:55:46

标签: java java-9 jvm-arguments jshell

我要执行以下操作:

jshell -v -Duser.country=FR -Duser.language=fr

例如获得个性化的Locale.getDefault()

2 个答案:

答案 0 :(得分:3)

$ jshell -R -Dtest1=one
|  Welcome to JShell -- Version 11.0.1
|  For an introduction type: /help intro

jshell> System.getProperty("test1")
$1 ==> "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

答案 1 :(得分:2)

一种可行的方法是使用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的本届会议。可以使用-retain选项保留设置,因此如果您使用

/set start -retain

然后,您下次调用jshell工具时也会加载设置的启动脚本。