Skip to content

v0.90.0

Compare
Choose a tag to compare
@maxandersen maxandersen released this 18 Feb 08:58
· 439 commits to main since this release

Changelog

Small changes this time with a big impact.

-i for interactive without sources

You always could to jbang --interactive <your.java|jsh|jar|gav> to have jbang start up your application/script within the jshell interpreter. Which is great but what if you just wanted to try out some API's without having to bother making a file to get started?

Now you can - just use jbang --interactive or jbang -i for short and you have a jshell. Of course that in itself is not interesting, but when you combine it with --deps it does become interesting. i.e. below is an example of starting jbang in interactive mode with access to h2 and jandex libraries.

jbang --deps com.h2database:h2:LATEST,org.jboss:jandex:2.4.2.Final -i
WARNING: Using incubator modules: jdk.incubator.vector, jdk.incubator.foreign
|  Welcome to JShell -- Version 17
|  For an introduction type: /help intro

jshell> import org.jboss.jandex.*;

jshell> Index.of(org.h2.Driver.class);
$2 ==> org.jboss.jandex.Index@9f48198

-c for code snippet execution

jbang now can execute java code directly allowing you to process standard input to make great one-liners like:

$ echo "hello world" | jbang -c 'lines().forEach(s->println(s.substring(6)))`
world

or this check for how many 5 letter words contains Man's best friend?

$ cat 5letterwords.txt | jbang -c 'lines().filter(s->s.contains("dog")).forEach(p->println(p))'
WARNING: Using incubator modules: jdk.incubator.foreign, jdk.incubator.vector
bedog
dogal
dogey
doges
doggy
doggo
dogie
dogly
dogma
dogra
undog

In the last example you will notice a few things:

  1. -c enables that the first argument is treated as code instead of a script
  2. a top-level method called 'lines()' is available to read lines from System.in
  3. println top-level method is available to easily print.

We got more ideas on adding some top-level methods to enable using java on
the command line.

And of course you can combine -c with --interactive and --deps and even
-s myscripts.jsh to load your own top-level methods.

Enjoy and Stay tuned :)

🚀 Features


Contributors

We'd like to thank the following people for their contributions:
Tako Schotanus, Max Rydahl Andersen, GitHub