How to pass JVM options to jshell while starting it
Asked Answered
T

2

8

I want to do the following :

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

So as to get for example a personalized Locale.getDefault().

Threonine answered 21/12, 2018 at 23:55 Comment(0)
S
6
$ jshell -R -Dtest1=one
|  Welcome to JShell -- Version 11.0.1
|  For an introduction type: /help intro

jshell> System.getProperty("test1")
$1 ==> "one"

It's documented in the help options

$ 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
Sunday answered 22/12, 2018 at 5:18 Comment(0)
E
3

One possible way to do that could be to use a startup script e.g. setLocale.jsh where the content of the script would be :

java.util.Locale.setDefault(java.util.Locale.CANADA) // set your locale

then further you can use on the jshell command line

/set start <path to setLocale.jst>

and ensure resetting the state to apply the change

/reset

to verify the change in Locale, you can do

java.util.Locale.getDefault()   // prints en_CA

Do note, the above implies only to the present session of jshell. A setting can be preserved with -retain option, so if you use

/set start -retain

then the set startup script will be loaded on your next invocation of the jshell tool as well.

Excessive answered 22/12, 2018 at 2:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.