Intro
Want to learn, explore or use Java instantly without setup ?
Do you like Java but use python, groovy, kotlin or similar languages for scripts, experimentation and exploration ?
Ever wanted to just be able to run java from anywhere without any or very minimal setup ?
Ever tried out Java 11+ support for running .java
files directly in your shell but felt it was a bit too cumbersome ?
Then try jbang
which lets you do this:
$ jbang init --template=cli hello.java
$ jbang hello.java Max!
[jbang] Resolving dependencies...
[jbang] Resolving info.picocli:picocli:4.6.3...Done
[jbang] Dependencies resolved
[jbang] Building jar...
Hello Max!
$ jbang hello.java -h
Usage: hello [-hV] <greeting>
hello made with jbang
<greeting> The greeting to print
-h, --help Show this help message and exit.
-V, --version Print version information and exit.
Instant app generated built using java and picocli as a dependency that was fetched as needed for the compilation and execution.
JBang goes beyond more than just easy scripting; you can use jbang
to launch any kind of java application or library packaged as a jar available locally, via http/https download or in a Maven repository.
Features
-
.java
Scripting for Java 8 and upwards -
.jsh
via JShell from Java 9 and upwards -
.kt
via kotlinc (EXPERIMENTAL) -
.groovy
via groovyc (EXPERIMENTAL) -
Extract codeblocks from Markdown files (
.md
) (EXPERIMENTAL) -
Works on Windows, OSX and Linux and AIX
-
Install using curl, power shell, SDKMan (/), Homebrew (), Chocolatey () or Scoop ()
-
If needed will automatically install Java and even a Java editor (vscodium) for editing
-
Installation of scripts to user
PATH
-
Include multiple files and sources
-
Dependency declarations using
//DEPS <gav>
for automatic dependency resolution -
Control compile and runtime options with
//COMPILE_OPTIONS <flags>
,//NATIVE_OPTIONS <flags>
and//RUNTIME_OPTIONS <flags>
-
Compiled jar and Dependency resolution caching
-
native-image generation (
--native
) -
Launch with debug enabled for instant debugging from your favorite IDE
-
Transparent launch of JavaFX Applications on Java 8 and higher
-
Can be used for writing plugins to other cli’s like
kubectl
-
Init templates to get started easily (
jbang init -t cli hello.java
) -
Generate gradle and IDE config with dependencies for easy editing in your favorite IDE (
jbang edit myfile.java
) -
Maven and Gradle plugins for easy integration with your favorite build tool
To use it install jbang
and run jbang yourscript.java
Requirements
Tested and verified to use on OSX, Linux, AIX, Windows (incl. command.exe, cygwin and mingw shells).
AIX requires the GNU |