JShell guide - modules

created onJanuary 28, 2022

setting the module configuration

In order to be able to access modules that are not part of the JDK, the module path must be set according to the location of those modules.

The module path can be set on the commandline when starting jshell:

jshell --module-path whateverPath --add-modules whatever.module

or in jshell with the command :

jshell> /env -module-path whateverPath -add-modules whatever.module

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

declaring exports of modules

The parameter can be used to export packages of a module. From the jshell online help, section ‘context’:

" --add-exports <module>/=<target-module>(,<target-module>)* updates <module> to export <package> to <target-module>, regardless of module declaration. can be ALL-UNNAMED to export to all unnamed modules. In jshell, if the is notspecified ( no = ) then ALL-UNNAMED is used."
jshell manual

Note that setting the Module path 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.