Add jbang: single-file Java with JBang 0.132.1 on JDK 25 (deps, compact source files, Spring Boot, templates, native)
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b6ZEVHGaYy15HAxRzy
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
7c677a39d2
commit
ddc3ec9d90
@@ -0,0 +1,34 @@
|
||||
# Cold run (empty JBang cache) then warm run, same script
|
||||
$ jbang Hello.java Ankur
|
||||
[jbang] Building jar for Hello.java...
|
||||
Hello, Ankur!
|
||||
Running on Java 25 (Eclipse Adoptium)
|
||||
[wall clock: 5.745s]
|
||||
|
||||
$ jbang Hello.java Ankur
|
||||
Hello, Ankur!
|
||||
Running on Java 25 (Eclipse Adoptium)
|
||||
[wall clock: 2.338s]
|
||||
|
||||
$ jbang info tools Hello.java
|
||||
{
|
||||
"originalResource": "Hello.java",
|
||||
"backingResource": "/tmp/work/jbang/Hello.java",
|
||||
"applicationJar": "/tmp/tmp.RXxYNQBWOn/cache/jars/Hello.java.af0224835723899ff208d77a8e96fa9f8c064e617b7dbc225df29b5021aab8a0/Hello.jar",
|
||||
"mainClass": "Hello",
|
||||
"resolvedDependencies": [],
|
||||
"javaVersion": "25",
|
||||
"requestedJavaVersion": "25+",
|
||||
"availableJdkPath": "/tmp/tools/jdk-25.0.5.1+2",
|
||||
"compileOptions": [
|
||||
"-g",
|
||||
"-parameters"
|
||||
],
|
||||
"sources": [
|
||||
{
|
||||
"originalResource": "Hello.java",
|
||||
"backingResource": "/tmp/work/jbang/Hello.java"
|
||||
}
|
||||
],
|
||||
"docs": {}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
$ jbang CompactHello.java
|
||||
[jbang] Building jar for CompactHello.java...
|
||||
Hello from a compact source file
|
||||
Implicit class: CompactHello
|
||||
@@ -0,0 +1,19 @@
|
||||
$ jbang Greeter.java --help
|
||||
[jbang] Resolving dependencies...
|
||||
[jbang] info.picocli:picocli:4.7.7
|
||||
[jbang] Dependencies resolved
|
||||
[jbang] Building jar for Greeter.java...
|
||||
Usage: greeter [-hlV] [-n=<times>] <name>
|
||||
Greets people, optionally loudly.
|
||||
<name> Who to greet.
|
||||
-h, --help Show this help message and exit.
|
||||
-l, --loud Shout the greeting.
|
||||
-n, --times=<times> Repeat count (default: 1).
|
||||
-V, --version Print version information and exit.
|
||||
|
||||
$ jbang Greeter.java --loud --times 2 Ankur
|
||||
HELLO, ANKUR!
|
||||
HELLO, ANKUR!
|
||||
|
||||
$ jbang info classpath Greeter.java
|
||||
/tmp/tmp.RXxYNQBWOn/cache/jars/Greeter.java.5779a46c55f3fbe373ce3efdcca5ec2bb019e2179eee9b52e6fc7d76d8acbec9/Greeter.jar:/root/.m2/repository/info/picocli/picocli/4.7.7/picocli-4.7.7.jar
|
||||
@@ -0,0 +1,11 @@
|
||||
$ echo '{"a":1,"b":[1,2,{"c":null}]}' | jbang Pretty.java
|
||||
[jbang] Resolving dependencies...
|
||||
[jbang] tools.jackson.core:jackson-databind:3.3.0
|
||||
[jbang] Dependencies resolved
|
||||
[jbang] Building jar for Pretty.java...
|
||||
{
|
||||
"a" : 1,
|
||||
"b" : [ 1, 2, {
|
||||
"c" : null
|
||||
} ]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
$ jbang Main.java
|
||||
[jbang] Building jar for Main.java...
|
||||
=== multi-file JBang demo ===
|
||||
ONE SCRIPT, TWO SOURCES, ONE RESOURCE!
|
||||
@@ -0,0 +1,8 @@
|
||||
$ jbang SpringApp.java
|
||||
[log lines that matter, timestamps/PIDs trimmed]
|
||||
INFO demo.SpringApp : Starting SpringApp using Java 25.0.5.1 with PID 22275 (/tmp/tmp.RXxYNQBWOn/cache/jars/SpringApp.java.3f7221da265b2f6554670ab927989c9962b804151b313b88dc6e785f1aba42b3/SpringApp.jar started by root in /tmp/work
|
||||
INFO o.s.boot.tomcat.TomcatWebServer : Tomcat started on port 8089 (http) with context path '/'
|
||||
INFO demo.SpringApp : Started SpringApp in 4.875 seconds (process running for 5.977)
|
||||
|
||||
$ curl -s localhost:8089/hello
|
||||
Hello from a single-file Spring Boot app
|
||||
@@ -0,0 +1,8 @@
|
||||
$ jbang broken/SpringDefaultPackage.java
|
||||
[log lines that matter, timestamps/PIDs trimmed]
|
||||
INFO SpringDefaultPackage : Starting SpringDefaultPackage using Java 25.0.5.1 with PID 22621 (/tmp/tmp.RXxYNQBWOn/cache/jars/SpringDefaultPackage.java.51714cd16af051bf7eb9f5a0f0d4aeb0f3bd08b4e81750139ad135d9e660ca37/SpringDefaultP
|
||||
** WARNING ** : Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package.
|
||||
APPLICATION FAILED TO START
|
||||
The bean 'errorPageRegistrarBeanPostProcessor', defined in class path resource [org/springframework/boot/web/servlet/support/ErrorPageFilterConfiguration.class], could not be registered. A bean with that name has already been defi
|
||||
|
||||
(no HTTP answer on port 8090 after 120 s)
|
||||
@@ -0,0 +1,13 @@
|
||||
$ jbang broken/CompactNoJava25.java
|
||||
[jbang] Downloading JDK 21. Be patient, this can take several minutes...
|
||||
[jbang] Installing JDK 21...
|
||||
[jbang] Default JDK set to 21 (21.0.13.1+2-LTS [fixed], 21-jbang, /tmp/tmp.RXxYNQBWOn/cache/jdks/21, [Ga, Jdk]))
|
||||
[jbang] Building jar for CompactNoJava25.java...
|
||||
/tmp/work/jbang/broken/CompactNoJava25.java:2: error: unnamed classes are a preview feature and are disabled by default.
|
||||
void main() {
|
||||
^
|
||||
(use --enable-preview to enable unnamed classes)
|
||||
1 error
|
||||
[jbang] [ERROR] Error during compile
|
||||
[jbang] Run with --verbose for more details. The --verbose must be placed before the jbang command. I.e. jbang --verbose run [...]
|
||||
[exit status: 1]
|
||||
@@ -0,0 +1,6 @@
|
||||
$ jbang broken/MissingDep.java
|
||||
[jbang] Resolving dependencies...
|
||||
[jbang] info.picocli:picocli:9.9.9
|
||||
[jbang] [ERROR] Could not read artifact descriptor for info.picocli:picocli:jar:9.9.9
|
||||
[jbang] Run with --verbose for more details. The --verbose must be placed before the jbang command. I.e. jbang --verbose run [...]
|
||||
[exit status: 1]
|
||||
@@ -0,0 +1,4 @@
|
||||
$ jbang broken/NeedsJava99.java
|
||||
[jbang] [ERROR] No suitable JDK was found for requested version: 99
|
||||
[jbang] Run with --verbose for more details. The --verbose must be placed before the jbang command. I.e. jbang --verbose run [...]
|
||||
[exit status: 4]
|
||||
@@ -0,0 +1,26 @@
|
||||
$ jbang template add -f jbang-catalog.json --name tool '{basename}.java=tool.java.qute'
|
||||
[jbang] Template 'tool' added to 'jbang-catalog.json'
|
||||
|
||||
$ cat jbang-catalog.json
|
||||
{
|
||||
"templates": {
|
||||
"tool": {
|
||||
"file-refs": {
|
||||
"{basename}.java": "tool.java.qute"
|
||||
},
|
||||
"description": "Picocli CLI skeleton",
|
||||
"properties": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ jbang init -t tool Slugify.java
|
||||
[jbang] File initialized. You can now run it with 'jbang Slugify.java' or edit it using 'j
|
||||
|
||||
$ sed -n 9,10p Slugify.java
|
||||
|
||||
@Command(name = "Slugify", mixinStandardHelpOptions = true, version = "Slugify 0.1")
|
||||
|
||||
$ jbang Slugify.java Hello World
|
||||
[jbang] Building jar for Slugify.java...
|
||||
Slugify processed: Hello World
|
||||
@@ -0,0 +1,11 @@
|
||||
$ jbang alias list
|
||||
greeter
|
||||
Picocli greeter CLI
|
||||
/tmp/work/jbang/Greeter.java
|
||||
pretty
|
||||
Pretty-print JSON from stdin (Jackson 3)
|
||||
/tmp/work/jbang/Pretty.java
|
||||
|
||||
$ jbang greeter -n 2 Ankur
|
||||
Hello, Ankur!
|
||||
Hello, Ankur!
|
||||
@@ -0,0 +1,10 @@
|
||||
$ jbang export portable -O /tmp/greeter-portable.jar Greeter.java
|
||||
[jbang] Updating jar...
|
||||
[jbang] Exported to /tmp/greeter-portable.jar
|
||||
|
||||
$ ls greeter-portable*
|
||||
greeter-portable.jar
|
||||
|
||||
$ java -jar greeter-portable.jar Ankur
|
||||
Hello, Ankur!
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
# native-image 25.0.4 2026-07-21
|
||||
$ jbang --native Hello.java Native
|
||||
[jbang] Building jar for Hello.java...
|
||||
[jbang] log: /tmp/jbang18248476024474165891native-image
|
||||
Hello, Native!
|
||||
Running on Java 25 (Oracle Corporation)
|
||||
[wall clock: 154.486s]
|
||||
|
||||
$ jbang --native Hello.java Native # second run, binary cached
|
||||
Hello, Native!
|
||||
Running on Java 25 (Oracle Corporation)
|
||||
[wall clock: 1.350s]
|
||||
|
||||
$ ls -la $JBANG_DIR/cache/jars/Hello.java.*/
|
||||
7696
|
||||
4096 .
|
||||
4096 ..
|
||||
7866632 Hello.bin
|
||||
1895 Hello.jar
|
||||
|
||||
$ Hello.bin Native # the cached binary, no JBang, no JVM
|
||||
Hello, Native!
|
||||
Running on Java 25 (Oracle Corporation)
|
||||
[wall clock: 0.005s]
|
||||
|
||||
$ java -cp Hello.jar Hello Native # same program on the JVM
|
||||
Hello, Native!
|
||||
Running on Java 25 (Oracle Corporation)
|
||||
[wall clock: 0.277s]
|
||||
@@ -0,0 +1,37 @@
|
||||
$ jbang https://ankurm.com/wp-content/uploads/2026/12/Hello.java Remote
|
||||
[jbang] https://ankurm.com/wp-content/uploads/2026/12/Hello.java is not from a trusted source thus not running it automatically.
|
||||
|
||||
If you trust the url to be safe to run you can do one of the following
|
||||
|
||||
(1) Trust once: Add no trust, only allow access to this URL for the duration of this run
|
||||
(2) Trust limited url in future: https://ankurm.com/wp-content/uploads/2026/12/
|
||||
(0) Cancel
|
||||
|
||||
[jbang] Type in your choice and hit enter. Will automatically select option (0) after 30 seconds.
|
||||
[jbang] Timeout reached, selecting option (0)
|
||||
[jbang] [ERROR] https://ankurm.com/wp-content/uploads/2026/12/Hello.java is not from a trusted source and user did not confirm trust thus aborting.
|
||||
If you trust the url to be safe to run are here a few suggestions:
|
||||
Limited trust:
|
||||
jbang trust add https://ankurm.com/wp-content/uploads/2026/12/
|
||||
Trust all subdomains:
|
||||
jbang trust add *.ankurm.com
|
||||
Trust all sources (WARNING! disables url protection):
|
||||
jbang trust add *
|
||||
|
||||
For more control edit ~/.jbang/trusted-sources.json
|
||||
|
||||
[jbang] Run with --verbose for more details. The --verbose must be placed before the jbang command. I.e. jbang --verbose run [...]
|
||||
[exit status: 10]
|
||||
|
||||
$ jbang trust add https://ankurm.com/wp-content/uploads/
|
||||
[jbang] Trusting permanently: [https://ankurm.com/wp-content/uploads/]
|
||||
|
||||
$ jbang https://ankurm.com/wp-content/uploads/2026/12/Hello.java Remote
|
||||
[jbang] Building jar for Hello.java...
|
||||
Hello, Remote!
|
||||
Running on Java 25 (Eclipse Adoptium)
|
||||
|
||||
$ grep -v '^//' $JBANG_DIR/trusted-sources.json
|
||||
[
|
||||
"https://ankurm.com/wp-content/uploads/"
|
||||
]
|
||||
Reference in New Issue
Block a user