To install the latest version, add the following to the lib/bld/bld-wrapper.properties file:
bld.extension-jbang=com.uwyn.rife2:bld-jbangFor more information, please refer to the extensions documentation.
@BuildCommand(summary = "Runs JBang script")
public void jbang() throws Exception {
new JBangOperation()
.fromProject(this)
.jBangArgs("--quiet")
.script("path/to/script.java")
.args("foo", "bar")
.execute();
}./bld jbang
To set trusts before running a script:
@BuildCommand(summary = "Runs JBang script")
public void jbang() throws Exception {
var trusts = List.of("https://github.com/", "https://jbang.dev/");
var op = new JBangOperation().fromProject(this);
op.jBangArgs("trust", "add")
.jBangArgs(trusts)
.execute();
op.reset();
op.script("https://github.com/jbangdev/jbang-examples/blob/main/examples/helloworld.java")
.execute();
}By default, the extension uses an existing JBang installation when available, or downloads the latest release into the sandbox when none is found. Downloading requires a project.
To use a specific local installation:
new JBangOperation()
.fromProject(this)
.jBangHome("/path/to/.jbang")
.script("path/to/script.java")
.execute();To always use a downloaded JBang, ignoring any local installation:
new JBangOperation()
.fromProject(this)
.useDownloadedJBang()
.script("path/to/script.java")
.execute();See jBangHome(...)
and
useDownloadedJBang()
for details.
To download and use a specific JBang version via
version(...),
regardless of any local installation:
new JBangOperation()
.fromProject(this)
.version("0.143.0")
.script("path/to/script.java")
.execute();Common JBang options have dedicated setters such as:
verbose(...),
quiet(...),
offline(...),
fresh(...),
insecure(...),
stacktrace(...),
config(...),
netrc(...),
etc.
new JBangOperation()
.fromProject(this)
.offline(true)
.fresh(true)
.config("custom-jbang.properties")
.script("path/to/script.java")
.execute();Anything else can be passed through jBangArgs(...):
new JBangOperation()
.fromProject(this)
.jBangArgs("--debug")
.script("path/to/script.java")
.execute();The child JBang process can be tuned without changing the JBang arguments:
new JBangOperation()
.fromProject(this)
.env("JAVA_HOME", "/path/to/jdk")
.timeout(120)
.inheritIO(false)
.outputConsumer(System.out::println)
.exitOnFailure(false)
.script("path/to/script.java")
.execute();env(name, value)— set environment variables for the JBang child.timeout(seconds)— execution timeout, in seconds. Default is600; use a negative value for no timeout. Zero is rejected.inheritIO(boolean)— let the child inherit the current JVM's I/O. Default istrue.outputConsumer(Consumer<String>)— receive captured output wheninheritIO(false).exitOnFailure(boolean)— throw on a non-zero JBang exit status. Default istrue.
Call reset()
to clear per-script settings while keeping the launcher, version pin, timeout and I/O configuration:
var op = new JBangOperation()
.fromProject(this)
.jBangHome("/path/to/.jbang")
.timeout(120);
op.script("scripts/first.java")
.args("input.txt")
.execute();
op.reset();
op.script("scripts/second.java")
.args("other.txt")
.execute();Or just create a fresh operation per script — reset()
is only a convenience.
Please check the documentation for all available configuration options.