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.

Debug info

JBang since version 0.100 compiles with debug info enabled by default. You can use -C=-g to tweak how much debug info is included: jbang -C=-g=lines,vars,source or to turn it off use `jbang -C=-g=none".

Debug jbang itself

Java itself will add JAVA_TOOL_OPTIONS which will apply to jbang too.

For finer and more explicit control the scripts, jbang will add JBANG_JAVA_OPTIONS to the call to jbang itself. Thus if you want to enable debug or other details for jbang set that environment variable.