Debugging
When running .java
scripts with jbang
you can pass the --debug
-flag and the script will enable debug,
suspend the execution and wait until you connect a debugger to port 4004.
jbang --debug helloworld.java
Listening for transport dt_socket at address: 4004
You can change the debug port and host by passing in a interface pattern and number to the debug argument, e.g., --debug=*:4321
.
This will make it use port 4321 and make it listen on all ('*') network interfaces.
Be sure to put a breakpoint in your IDE/debugger before you connect to make the debugger actually stop when you need it. |
Additionally you can pass in a additional key/value options to the debug string, e.g., --debug=server=n,suspend=y
. To have the debugger
connect to the IDE and suspend the execution when it connects as opposed to having the IDE connect.
You can see the key/value options supported in OpenJDK JPDA documentation.