Beyond Hello World!

less than 1 minute read

A simple script you can run with jbang is "Hello World" using jshell (.jsh).

    System.out.println("Hello " + ((args.length>0)?args[0]:"jbang"));

You can run the above by putting it in a file named: hello.jsh and run jbang hello.jsh.

To expand on this we will make a Java file (.java) which uses an external dependency to make the text a bit more fancy.

In this case we’ll use a library called jfiglet.

We use //DEPS com.github.lalyos:jfiglet:0.0.8 to declare this script should run using the dependency with group id: com.github.lalyos, artifact id: jfiglet and with the version 0.0.8.

These are called "artifacts coordinates" or "maven coordinates" as the system originates from the Maven build system; but is today used in almost all Java projects. You can use sites like to locate the coordinates of projects, and otherwise find them on the website or source repository of the project them self.

Below is a instance preconfigured with jbang ready to run using the figlet dependency.

Try and press the Run button to see how it works and then try edit the code to see how it pick up the changes between each run.

Leave a comment