JBang cheatsheet (2021)
source link: http://www.mastertheboss.com/java/jbang-cheatsheet-2021/?utm_campaign=jbang-cheatsheet-2021
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Here is my JBang cheatsheet which can help as a reference to code self-contained source-only Java programs with unmatched ease.
Getting started with JBang
Install JBang on Linux
curl -Ls https://sh.jbang.dev | bash -s - app setup
Create a JBang class from a template
jbang init --template=hello helloworld.java
List of available JBang templates
jbang template list
Run a Java class
jbang helloworld.java
Update JBang
jbang version --update
Running a Java class in a JAR file
jbang jgroups-4.2.15.Final.jar --main=org.jgroups.tests.McastReceiverTest
Running a Java class using Maven GAV coordinates
jbang org.jgroups:jgroups:5.1.9.Final --main=org.jgroups.tests.McastReceiverTest
Configuration
Adding dependency
//DEPS log4j:log4j:1.2.17
Adding Managed Dependencies (BOM)
//DEPS io.quarkus:quarkus-bom:1.11.0.Final@pom //DEPS io.quarkus:quarkus-resteasy //DEPS io.quarkus:quarkus-smallrye-openapi
Using System properties in the comments
//DEPS org.openjfx:javafx-graphics:11.0.2:${os.detected.jfxname}
Using Environment variables in the comments
//DEPS org.openjfx:javafx-graphics:11.0.2:${env.jfxname}
Repository for dependencies (maven repository + custom repository)
//REPOS mavencentral,acme=https://maven.acme.local/maven
Adding file resources
//FILES resource.properties //FILES META-INF/resources/index.html=index.html
JDK configuration
Setting JDK in your code
//JAVA 11 will force use of Java 11. //JAVA 13+ will require at least java 13. Java 13 or higher will be used.
Install a JDK
jbang jdk install 17
Uninstall a JDK
jbang jdk uninstall 14
List available JDK
jbang jdk list
Setting default JDK
jbang jdk default 12
Debugging and JDK Settings
Debugging a Java class
jbang --debug helloworld.java
Setting java and javac options
//JAVAC_OPTIONS -source 11 //JAVA_OPTIONS -Xms128m -Xmx512m
Catalog
Install an app from the Catalog
jbang app install CamelJBang@apache/camel
List of available apps
jbang app list
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK