JShell guide - working with the classpath

created onJanuary 28, 2022

setting the classpath

In order to be able to access classes in libs or class files that are not part of the JDK, the classpath must be set according to the location of those libs and class files

The classpath can be set on the commandline when starting jshell:

jshell --class-path <classpath>

or in jshell with the command :

jshell> /env -class-path ~/src/java/lib | Setting new options and restoring state. jshell>

A classpath is a list of classpath items. Classpath items can be directories containing class files, JAR files and ZIP archives. To separate items on Windows, use the semicolon ‘;’, on other systems use the colon ‘:’.

Note that setting the classpath with causes the execution state to be reset and all snippets entered in the current session are run again. The output of the snippets will not be displayed, however any error during the replay of the snippets will be displayed.

displaying the classpath

The classpath is displayed with the command without any parameter:

jshell> /env | --class-path ~/src/java/lib jshell>