Unleash the power of Java https://www.jbang.dev/
///usr/bin/env jbang "$0" "$@" ; exit $?
class Hello {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
$ jbang Hello.java
$ jbang --debug Hello.java
$ chmod u+x
$ ./Hello.java
$ jbang template list
$ jbang init --template=cli helloworld.java
$ jbang init HelloCli.java "generate hello command with picocli library"
|
//JAVA 8
|
Assigned version in Script
|
|
//JAVA 11+
|
Java 11 or higher
|
|
jbang --java 8 Hello.java
|
Assigned version from CLI
|
|
jbang jdk list --available
|
List available JDKs
|
//JAVAC_OPTIONS -parameters
//JAVA_OPTIONS -Dnick=xxx
//JAVA_OPTIONS -Dserver.port=8081 -D spring.application.name=app1
//PREVIEW
///usr/bin/env jbang "$0" "$@" ; exit $?
//PREVIEW
//JAVA 21
void main() {
System.out.println("Hello World");
}
//SOURCES UserService.java
//SOURCES impl/UserServiceImpl.java
//FILES application.properties
//FILES META-INF/resources/index.html=index.html
//FILES META-INF/resources/jquery.js=https://code.jquery.com/jquery-3.6.0.min.js
//FILES templates/HelloWorld.txt.mtl=templates/HelloWorld.txt.mtl
**Resource import format**: //FILES <mountpoint>[=<sourcefile>]
///usr/bin/env jbang "$0" "$@" ; exit $?
//KOTLIN 1.8.21
//DEPS org.jetbrains.kotlin:kotlin-bom:1.8.21@pom
//DEPS org.jetbrains.kotlin:kotlin-stdlib
public fun main() {
println("Hello World");
}
///usr/bin/env jbang "$0" "$@" ; exit $?
//GROOVY 4.0.12
println("Hello World");
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS net.datafaker:datafaker:1.9.0
import net.datafaker.Faker;
Faker faker = new Faker();
$ jbang --native Hello.java
// https://github.com/linux-china/jbang-spring-native
// https://github.com/GoodforGod/graalvm-hint
//DEPS systems.manifold:manifold-all:2023.1.10
//DEPS org.projectlombok:lombok:1.18.28
//DEPS org.slf4j:slf4j-simple:2.0.7
//DEPS libs/local.jar
//DEPS eu.maveniverse.maven.plugins:toolbox:0.1.9:cli@fatjar
//DEPS org.springframework.boot:spring-boot-dependencies:2.7.11@pom
//DEPS org.springframework.boot:spring-boot-starter
//DEPS io.quarkus:quarkus-bom:2.9.2.Final@pom
//DEPS io.quarkus:quarkus-resteasy
//REPOS central,spring-release=https://repo.spring.io/release
//REPOS central,spring-milestone=https://repo.spring.io/milestone
**Well-known repositories**:
* central - https://repo1.maven.org/maven2/
* google - https://maven.google.com/
* jitpack - https://jitpack.io/
$ jbang alias add --name hello https://github.com/jbangdev/jbang-examples/blob/HEAD/examples/helloworld.java
$ jbang hello
$ jbang alias list
$ jbang alias list --show-origin
{
"aliases": {
"hello": {
"script-ref": "hello.java",
"description": "Script that says hello back for each argument"
}
}
|
1. jbang-catalog.json in current directory
|
|
2. jbang-catalog.json in parent directory util the root diretory
|
|
3. $HOME/.jbang/jbang-catalog.json
|
|
4. JBangHub: https://github.com/jbanghub
|
|
jbang hello@acme
|
hello alias in acme/jbang-catalog/jbang-catalog.json
|
|
jbang hello@acme/mycatalog
|
hello alias in acme/mycatalog/jbang-catalog.json
|
|
jbang hello@acme/mycatalog/dev
|
hello alias in acme/mycatalog/jbang-catalog.json in dev branch
|
|
jbang hello@acme~experimental
|
hello alias in acme/jbang-catalog/experimental/jbang-catalog.json
|
|
jbang hello@example.com
|
hello alias found in https://example.com/jbang-catalog.json
|
$ jbang catalog add --name acme acme
$ jbang catalog add --name mycatalog acme/mycatalog
$ jbang catalog list
|
jbang --fresh
|
Use none-cached resources
|
|
jbang info tools Hello.java
|
Prints a json description of JBang script
|
$ jbang app install <scriptRef>
$ $ jbang app install --name app1 <scriptRef>
$ jbang app list
$ jbang app uninstall <name>
///usr/bin/env jbang "$0" "$@" ; exit $?
//JAVA 17
//DEPS info.picocli:picocli:4.7.3
//SOURCES src
//FILES resources
|
jbang export fatjar
|
Exports an executable fat jar with all dependencies
|
|
jbang export portable
|
Exports jar together with dependencies in pom.xml
|
|
jbang export native
|
Exports native executable
|
|
jbang export mavenrepo
|
Exports directory that can be used to publish as a maven repository
|
|
jbang export jlink
|
Export app with Java runtime embedded
|
export OPENAI_API_KEY=sk-xxxxxxx-x-xxxxxx
jbang init gh.java "connect to github an fetch all repositories under jbangdev and collect how many stars they have"
|
JBANG_DEFAULT_JAVA_VERSION
|
11
|
|
JBANG_DOWNLOAD_SOURCES
|
true
|
|
JBANG_EDITOR
|
Code editor, such as zed, code
|
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.