|
| 1 | += Self-Contained Executables |
| 2 | +:idprefix: |
| 3 | +:idseparator: - |
| 4 | +ifndef::env-github[] |
| 5 | +:icons: font |
| 6 | +endif::[] |
| 7 | +ifdef::env-github[] |
| 8 | +:caution-caption: :fire: |
| 9 | +:important-caption: :exclamation: |
| 10 | +:note-caption: :paperclip: |
| 11 | +:tip-caption: :bulb: |
| 12 | +:warning-caption: :warning: |
| 13 | +endif::[] |
| 14 | + |
| 15 | +Self-contained executables are executables that you can run without needing a pre-existing runtime to be installed. |
| 16 | + |
| 17 | +GraalVM's native-image is one way of doing this, but GraalVM also deal with optimizing the runtime for performance by doing additional compilation/optimization. |
| 18 | + |
| 19 | +This section is not about GraalVM's native-image, but about other ways of creating self-contained executables. |
| 20 | + |
| 21 | +== JBundle |
| 22 | + |
| 23 | +https://jbundle.avelino.run/[JBundle] can be used with JBang to compile your Java scripts into standalone self-contained executables. |
| 24 | + |
| 25 | +== Why JBundle? |
| 26 | + |
| 27 | +GraalVM's native-image can be challenging to use due to slow compilations, reflection configurations, and libraries that might not work well in native image. |
| 28 | + |
| 29 | +JBundle offers a practical and easy to use solution by bundling a minimal JVM runtime with your uberjar into a single executable. The result is a single executable file, without any external dependencies, and with full JVM compatibility. |
| 30 | + |
| 31 | +=== Creating Self-Contained Executables with JBundle |
| 32 | + |
| 33 | +https://jbundle.avelino.run/[JBundle] makes it easy to create self-contained executables from JBang applications without the need for complex configuration. JBundle uses `jlink` to analyze your application and its dependencies, then generates a self-contained executable file with a minimal embedded JVM runtime providing only the necessary modules required by your application. |
| 34 | + |
| 35 | +* Step 0 - Create a JBang script (or use an existing application) |
| 36 | +** jbang init hello.java |
| 37 | +* Step 1 - create a JBang fatjar |
| 38 | +** jbang export fatjar hello.java |
| 39 | +* Step 2 - use JBundle to create a self-contained executable from the fatjar |
| 40 | +** jbundle build --input ./hello-fatjar.jar --output ./dist/hello |
| 41 | +* Step 3 - run the self-contained binary file |
| 42 | +** ./dist/hello |
| 43 | ++ |
| 44 | +Hello World |
| 45 | + |
| 46 | +=== JBundle Configuration |
| 47 | + |
| 48 | +Additional https://jbundle.avelino.run/user-guide/configuration[configuration options] can be specified on the command-line or stored in a `jbundle.toml` file in the local folder. |
| 49 | + |
| 50 | +```toml |
| 51 | +# jbundle.toml |
| 52 | + |
| 53 | +java_version = 25 |
| 54 | +profile = "server" |
| 55 | +jvm_args = ["-Xmx512m", "-XX:+UseZGC"] |
| 56 | +shrink = true |
| 57 | +appcds = false |
| 58 | +crac = false |
| 59 | +``` |
| 60 | + |
| 61 | +=== Limitations |
| 62 | + |
| 63 | +JBundle is currently only supported on Linux and MacOS. |
0 commit comments