Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging with JShell

I write a Java method in JShell and now I want to debug it. I would like to set breakpoints or at least step through an execution line-by-line. Does JShell have these debugging abilities?

like image 674
ChaimKut Avatar asked Dec 10 '18 10:12

ChaimKut


People also ask

How do you use JShell?

To start Jshell, first we must have installed Java 9 then open terminal in Linux or command prompt in windows and type jshell. It will start jshell session and displays a welcome message to the console. To display a simple “Hello Java” message, write print command without creating class and hit enter.

How do I skip a loop while debugging?

As a user I would suggest the following: make a hotkey to exit the loop in debugging mode, for example ctrl-shift-F11.


2 Answers

Just to clarify further, from the JEP: The Java Shell (Read-Eval-Print Loop) itself, the Non-Goals states :

Out of scope are graphical interfaces and debugger support. The JShell API is intended to allow JShell functionality in IDEs and other tools, but the jshell tool is not intended to be an IDE.

like image 77
Naman Avatar answered Sep 20 '22 14:09

Naman


There is some undocumented /debug command (Jshell in Java 11). After /help /debug command you can see:

jshell> /help /debug
  Display debugging information for the jshell tool implementation.
  0: Debugging off
  r: Tool level debugging on
  g: General debugging on
  f: File manager debugging on
  c: Completion analysis debugging on
  d: Dependency debugging on
  e: Event debugging on

Notice, if you write /help only there is no information about /debug command.

Out of Jshell there is jdb tool for debug.

like image 31
zemiak Avatar answered Sep 20 '22 14:09

zemiak