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
kscriptto Java and needed a name. From there came j’bang which is a "bad" spelling of how shebang is pronounced in French.
Why use gradle resource locators rather than ?
kscript used it and it’s nice as it is a one-liner and easily parsable.
How does this compare to ?
jbangI’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.
Why is JBang scripting examples using lower case class names ?
JBang works with any valid Java class names including Java’s standard camel case conventions. The scripting examples are using lower case because the scripts can be used as a command line tool. i.e.
./hello.java. Just like people are used to Java using camel case for class names, they are also used to using lower case for command line tools. So JBang is just following the convention most relevant for the scripting use case. Thus
HelloWorld.java; but if you prefer the latter you can always use it.
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.
And to be honest I built
jbangjust to see if I could and get my Java skills refreshed for the newer features in the language. Use it at your own risk :)
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.
HELP! My code formatter keeps breaking my
When using automated code formatting tools, some care and configuration must be made to prevent the tooling from rewriting and preventing
jbangfrom working as expected.
Use the following configuration blocks to correctly configure your tool:
Table 1. Configuration Tool Settings: Formatting Tool Configuration
CommentPragmas: '^[^ ]'
Scripting Java with a jBang - InfoQ - Alex Blewitt
jbang: Unleash the power of Java for shell scripting - DevNation Tech Talk - Max Rydahl Andersen
Creating java code and simplifying execution with JBang - Daniel Persson
Quarkus Insights #16: Quarkus with JBang - Quarkus Insights
jbang, a better Java? - Swiss JUG - Max Rydahl Andersen
JBang - Using Java to make Java better? - Virtual JUG - Max Rydahl Andersen
Self contained JDBC scripts with Groovy and jbang - Andres Almiray
Neo4j quickie - jbang and the command line - Gerrit Meier
How to build a CLI app in Java using jbang and picocli - Matthew Gilliard
Faster Feedback with Java, JBang, and TextMate - Manik Magar
JBang: Create Java scripts like a pro - Francesco Marchioni
6 things you can do with JBang but you can’t with Shell - Francesco Marchioni