JBang - Unleash the Power of Java 🚀
Quick Start
What is JBang?
JBang makes it easy to write and run Java scripts without traditional project setup. It handles:
-
Zero setup - Run
.java
files directly -
Dependency management - Declare with
//DEPS
, auto-resolve from Maven -
Multiple languages - Java, Kotlin, Groovy, JShell, Markdown
-
IDE integration - Full IDE support with
jbang edit
-
Native compilation - Generate native binaries with GraalVM
-
Script sharing - Via GitHub, catalogs, and aliases
Key Features
✅ Instant Java scripting - No build files, no project setup
✅ Dependency management - Maven-style deps with //DEPS
✅ Multiple file types - .java
, .jsh
, .kt
, .groovy
, .md
✅ IDE support - Full IntelliSense with jbang edit
✅ Cross-platform - Windows, macOS, Linux, AIX
✅ Native images - GraalVM native-image support
✅ Easy sharing - GitHub URLs, catalogs, aliases
✅ Template system - Quick start with jbang init
Installation
Quick Install (recommended):
curl -Ls https://sh.jbang.dev | bash -s - app setup
Package managers:
- SDKMan: sdk install jbang
- Homebrew: brew install jbangdev/tap/jbang
- Chocolatey: choco install jbang
- Scoop: scoop install jbang
See installation docs for more options.
Examples
Hello World
///usr/bin/env jbang "$0" "$@" ; exit $?
class hello {
public static void main(String[] args) {
System.out.println("Hello " + (args.length > 0 ? args[0] : "World"));
}
}
CLI App with Dependencies
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS info.picocli:picocli:4.6.3
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Parameters;
@Command(name = "hello", mixinStandardHelpOptions = true)
class hello implements Runnable {
@Parameters(index = "0", description = "The greeting to print")
private String greeting;
public static void main(String[] args) {
new CommandLine(new hello()).execute(args);
}
public void run() {
System.out.println("Hello " + greeting);
}
}
Web Server
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS com.sun.net.httpserver:http:20070405
import com.sun.net.httpserver.*;
import java.io.IOException;
import java.net.InetSocketAddress;
class WebServer {
public static void main(String[] args) throws IOException {
HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0);
server.createContext("/", exchange -> {
String response = "Hello from JBang!";
exchange.sendResponseHeaders(200, response.length());
exchange.getResponseBody().write(response.getBytes());
exchange.close();
});
server.start();
System.out.println("Server started at http://localhost:8000");
}
}
Common Commands
# Create new script from template
jbang init --template=cli myapp.java
# Run script with dependencies
jbang myapp.java
# Edit with full IDE support
jbang edit myapp.java
# Run remote script
jbang https://github.com/user/repo/blob/main/script.java
# Create alias for easy access
jbang alias add --name myapp myapp.java
# Export to traditional project
jbang export maven myapp.java
# Create native binary
jbang --native myapp.java
# Install as system command
jbang app install myapp.java
AppStore
Beyond scripting, JBang can launch any Java application packaged as a JAR. Check out the AppStore for examples and community-contributed scripts.
Documentation
Community
-
💬 Chat: Zulip Community
-
🐛 Issues: GitHub Issues
-
🛍️ App Store: JBang App Store
-
📚 Examples: jbang-examples
Contributing
We welcome contributions! Please see our Contributing Guide for details.
Thanks
JBang was heavily inspired by kscript by Holger Brand.
License
JBang is released under the MIT License.