FAQ

  1. Why the name j’bang?

    I was reading up on how to use the new shebang (#!) feature support in Java 10 and came up with the idea of port kscript to Java and needed a name. From there came j’bang which is a "bad" spelling of how shebang is pronounced in French.

  2. Why use gradle resource locators rather than ?

    kscript used it and it’s nice as it is a one-liner and easily parsable.

  3. How does this compare to ?

    After doing jbang I’ve learned about similar projects and thought it would be nice with some comparison;

    jgo: an alternative way to launch jars using maven coordinates. Implemented in python, depends on Java and Maven to be available. Not really for scripting but a novel way to launch java apps already packaged as a maven dependency.

  4. Why would I use Java to write scripts ? Java sucks for that…​ Use groovy, kotlin, scala, etc. instead!

    Well, does it really suck ? With Java 8 streams, static imports and greatly improved standard java libraries it is very close to what kscript and grape look like. With the following advantages:

    • works with plain Java without installing additional compiler/build tools

    • all IDE’s support editing .java files very well, content assist, etc.

    • great debugging

      And to be honest I built jbang just to see if I could and get my Java skills refreshed for the newer features in the language. Use it at your own risk :)

  5. Why not use normal shebang(#!) in the header ?

    You can use normal shebang (#!/usr/bin/env jbang) and Java 10+ will actually work with it from the command line. Not recommended though as many tools and especially IDE’s will start complaining about syntax errors as they don’t ignore the first line in this case.

    By using the // form it is treated as both a bash/shell file AND a valid java file and thus works everywhere a java file will work.

    It’s worth noting that Go uses a similar approach which is also where I learned it from.

  6. HELP! My code formatter keeps breaking my // directives!

    When using automated code formatting tools, some care and configuration must be made to prevent the tooling from rewriting and preventing jbang from working as expected.

    Use the following configuration blocks to correctly configure your tool:

    Table 1. Configuration Tool Settings:
    Formatting Tool Configuration

    Clang Format

    CommentPragmas:  '^[^ ]'