jbang
Run Java code from source without setup
TLDR
Initialize a simple Java class
Initialize a Java class (useful for scripting)
Use jshell to explore and use a script and any dependencies in a REPL editor
Setup a temporary project to edit a script in an IDE
Run a Java code snippet (Java 9 and later)
Run command-line application
Install a script on the user's $PATH
Install a specific version of JDK to be used with jbang
SYNOPSIS
jbang [GLOBAL OPTIONS] [SUBCOMMAND] SCRIPT [-- ARGS]
PARAMETERS
-h, --help
Show help message
-V, --version
Print version info
--verbose, -v
Increase output verbosity
--quiet, -q
Reduce output
--color={true|false|auto}
Control colored output
--interactive, -i
Enable interactive mode
--force
Force actions like overwrite
--fresh
Use fresh cache, ignore existing
--no-deps
Skip dependency resolution
--detect-jdk
Detect and use project JDK
--trust=SCRIPT
Trust a script
--edit=SCRIPT
Edit script with $EDITOR
--app=SCRIPT
Install as app
init [TEMPLATE]
Initialize new script
trust SCRIPT
Trust script permanently
list
List installed/trusted scripts
delete SCRIPT
Delete script cache
export --type={jar|native|uber} SCRIPT
Export to executable
DESCRIPTION
JBang is a versatile command-line tool designed to execute Java code as scripts without requiring build tools like Maven or Gradle. It automatically resolves dependencies from sources like Maven Central, manages Java runtimes via SDKMAN integration, and supports features like templating, packaging into JARs or native executables with GraalVM.
Users can write simple .java files with a shebang (#! /usr/bin/env jbang) for direct execution or run them via jbang Script.java. It excels in rapid prototyping, automation scripts, and sharing code snippets. JBang caches artifacts for speed, trusts scripts selectively for security, and offers subcommands for app management, editing, and exporting.
Perfect for developers wanting script-like simplicity with Java's power, it handles modules, main methods, and args seamlessly, making Java viable for shell scripting.
CAVEATS
Requires Java 8+; initial dependency downloads need internet. Not all Java features (e.g., some reflection) work in native mode. Shebang support varies by shell.
INSTALLATION
curl -s "https://jbang.dev" | bash -s - install
Or brew install jbang on macOS.
EXAMPLE
echo 'System.out.println("Hello " + args[0]);' | jbang run - Hello.java World
Outputs: Hello World
HISTORY
Created by Johan Andersen in 2020 as a Java equivalent to tools like babashka. First public release via GitHub; now at v0.22+. Gained popularity for simplifying Java CLI scripting, with integrations for Adoptium, SDKMAN.


