Quick JBang Scripting With IntelliJ Idea

This quick article shows how to install and use JBang’s IntelliJ Idea plugin to create JBang projects and scripts in no time.

  • Firstly, to get started quickly with JBang, we recommend having a look at this article: JBang: Create Java scripts like a pro
  • Next, let’s see how to install JBang Plugin on IntelliJ Idea (Community or Pro version). From the File Menu select Settings | Plugins.

From there, search and install the JBang Plugin. Here is my Plugins view, following up the installation:

Next, let’s see the top interesting features of this plugin.

JBang Project wizard

Firstly, you are now able to create JBang projects. The main advantage is that, besides you have an organized folder for your scripts, you can also set the JDK and the extra libraries to include in your project. This is typically a good choice, for example, if you are coding Quarkus scripts with JBang:

Within a JBang project, you can add a new JBang script in it. Every JBang script includes the Run Line Marker for ///usr/bin/env jbang as you can see from this snippet:

///usr/bin/env jbang "$0" "$@" ; exit $?

import static java.lang.System.*;

public class Hello {

    public static void main(String... args) {

        out.println("Hello World");

Besides, IntelliJ enables to run JBang script with just a right click, provided that:

  • file name end with ‘.java’, ‘.kt’, ‘.groovy’ or ‘.jsh’
  • file code should contain ///usr/bin/env jbang or //DEPS

JBang directives auto-complete

The top feature I love from this plug-in is the ability to auto-complete JBang directives. For example:

  • You can hit CTRL+SPACE to see the list of directives. Choose the one you want to add, for example “DEPS“.
  • Then, start typing your dependency
  • Hit again CTRL+SPACE to allow auto-completion of Maven GAV:

This is a killer combination to add dependencies in a matter of seconds.

The same goes for other options, for example to choose the JDK version for your scripts:

JDKs sync with JBang

Besides, the plugin will automatically sync the JDKs from JBang to IntelliJ IDEA

Integration with jbang-catalog.json

The plugin recognizes the file jbang-catalog.json as file to configure JBang Catalog:

Within the file, IntelliJ provides the JSON Schema for jbang-catalog.json and code completion for the script-ref section

Debugging JBang scripts

Finally, as for every Java source code, you can also debug JBang scripts in IntelliJ Idea by placing break points in it and choosing to “Debug” option at start: