The interesting thing about running JShell inside Eclipse is to use a project's classpath. This is how to run JShell inside Eclipse out of the box (given Java >=9 and Eclipse -- I have used 2019-09 -- are installed), using the currently selected project as the base line:
- Select "Run > External Tools > External Tools Configuration"
- Enter the following settings:
- Name: JShell
- Location: /usr/bin/jshell -- or whereever your jshell command is found on your system
- Working Directory: ${project_loc}
- Arguments: --class-path "${project_classpath}"
For people not aware of JShell, there is a very good tutorial by Robert Field, and tons of other web pages about it.
For the impatient reader, some hints:
- Inside JShell, you have some extra commands available after a prefix "/", most notable "/help"
- If you change anything in your code (in the Eclipse editor), this is not necessarily reflected in JShell. You need to call "/reset" first!
- You can define methods without a class, i.e. you can define functions. Syntax is similar to methods, though.
JShell as external tool inside Eclipse |