JShell guide - configuration

created onJanuary 28, 2022

the jshell configuration file

On Linux systems, the startup configuration is written to the file .
Windows and Mac OS users will find the file in the corresponding directory inside their home directory / user directory.

contains a map, each entry of the map is of the form:

<entry key="<key>" value="<value>"/>

This map holds any configuration setting like class path, module path, editor, etc as well as all the startup commands and the history. The term ‘kitchen sink’ comes to my mind while writing this.

Any configuration value that is set during a jshell session as well as the history is written to when the jshell terminates normally, i.e. by issuing the command . If the jshell process is terminated abruptly, i.e. by a , the configuration values set in the abruptly terminated session as well as the history are not written to .

persisting the configuration

For a file with path with the content

import java.time.*

and the following jshell command

jshell> /set start -retain DEFAULT ~/startup.jsh jshell>

the following line is written to (see section ‘The jshell Configuration File’):

<entry key="STARTUP" value="*␞DEFAULT␞␞import java.io.*; import java.math.*; import java.net.*; import java.nio.file.*; import java.util.*; import java.util.concurrent.*; import java.util.function.*; import java.util.prefs.*; import java.util.regex.*; import java.util.stream.*; ␞-␞~/test.jsh␞Dec 20, 2021, 5:48:03 PM␞import java.time.*␞"/>

That is, not the file path but the contents of the file are written to the map in . Thus, after the jshell startup has been configured, any script files involved in the configuration can be moved or be deleted without affecting the startup configuration.