Beyond Hello World!
A simple script you can run with
jbang is “Hello World” using jshell (
System.out.println("Hello " + ((args.length>0)?args:"jbang"));
You can run the above by putting it in a file named:
hello.jsh and run
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
//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
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 https://mvnrepository.com to locate the coordinates of projects, and otherwise find them on the website or source repository of the project them self.
Below is a repl.it instance preconfigured with
jbang ready to run
hello.java using the
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.