|
| 1 | + |
| 2 | +**NGE** is a modern Java library, you can build and distribute your application in several ways, depending on your target platform and user base. |
| 3 | + |
| 4 | +!!! tip |
| 5 | + The [template app](./getting-started.md) includes a **GitHub Actions** workflow that builds for all supported platforms using every available methods. |
| 6 | + You can use this as a reference or adapt it directly for your own project. |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +## Building for Desktop |
| 11 | + |
| 12 | +### Portable JAR |
| 13 | + |
| 14 | +To build a standalone JAR file: |
| 15 | + |
| 16 | + |
| 17 | +```bash |
| 18 | +./gradlew build |
| 19 | +``` |
| 20 | + |
| 21 | +or on Windows: |
| 22 | + |
| 23 | +```bash |
| 24 | +gradlew.bat build |
| 25 | +``` |
| 26 | + |
| 27 | +The output will be located at: |
| 28 | + |
| 29 | +``` |
| 30 | +dist/portable/yourapp-version-portable.jar |
| 31 | +``` |
| 32 | + |
| 33 | +This is the traditional approach to distributing Java applications. It's simple, cross-platform, and requires only a single build step. |
| 34 | + |
| 35 | +However, it has a few limitations: |
| 36 | + |
| 37 | +* Slightly longer startup time compared to native executables |
| 38 | +* Requires users to have **Java Runtime Environment (JRE) version 21 or higher** installed |
| 39 | + |
| 40 | +While you *can* manually bundle a JRE with your app, there's a better alternative, discussed next. |
| 41 | + |
| 42 | + |
| 43 | +### Installer |
| 44 | + |
| 45 | +This method packages the portable JAR **along with a JRE**, and wraps them in a platform-specific installer. It simplifies distribution and ensures your users don't need to install Java separately. |
| 46 | + |
| 47 | + |
| 48 | +```bash |
| 49 | +./gradlew buildInstaller |
| 50 | +``` |
| 51 | + |
| 52 | +or on Windows: |
| 53 | + |
| 54 | +```bash |
| 55 | +gradlew.bat buildInstaller |
| 56 | +``` |
| 57 | + |
| 58 | +The output will be located at: |
| 59 | + |
| 60 | +``` |
| 61 | +dist/yourapp-version-platform.setup |
| 62 | +``` |
| 63 | + |
| 64 | +!!! note |
| 65 | + You can only create an installer for the platform you’re currently on. To support multiple platforms, you’ll need to run this process on each one individually. |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | +### Native Executable (Recommended) |
| 70 | + |
| 71 | +The most optimized way to distribute your app is as a **native executable**, which provides: |
| 72 | + |
| 73 | +* Significantly faster startup times |
| 74 | +* No need for users to install a JRE |
| 75 | +* No need to bundle a JRE with your app |
| 76 | + |
| 77 | +!!! note |
| 78 | + Native builds require **GraalVM 24 or higher**. |
| 79 | + |
| 80 | + You can install it easily using [SDKMAN](https://sdkman.io/): |
| 81 | + |
| 82 | + ```bash |
| 83 | + sdk install java 24-graal |
| 84 | + ``` |
| 85 | + |
| 86 | + |
| 87 | +Depending on the complexity of your app, you might need to run the *tracing agent* to help GraalVM understand your app's dependencies. |
| 88 | + |
| 89 | +To do that you need to run |
| 90 | + |
| 91 | +```bash |
| 92 | +./gradlew traceNative |
| 93 | +``` |
| 94 | + |
| 95 | +and use all the features of your app. This will update the tracing files for GraalVM. |
| 96 | + |
| 97 | +When you are ready you can build the native executable with: |
| 98 | + |
| 99 | + |
| 100 | +```bash |
| 101 | +./gradlew buildNativeExecutable |
| 102 | +``` |
| 103 | + |
| 104 | +or on Windows: |
| 105 | + |
| 106 | +```bash |
| 107 | +gradlew.bat buildNativeExecutable |
| 108 | +``` |
| 109 | + |
| 110 | +The output will be located at: |
| 111 | + |
| 112 | +``` |
| 113 | +dist/yourapp-version-platform.buildNative/ |
| 114 | +``` |
| 115 | + |
| 116 | +This directory includes the executable along with all required dependencies and resources that you will need to ship alongside with your app. |
| 117 | + |
| 118 | + |
| 119 | +!!! note |
| 120 | + Native executables can **only** be built on the platform you're currently running. GraalVM does **not** support cross-compilation yet. |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | +## Building for Android |
| 125 | + |
| 126 | +TBD |
| 127 | + |
| 128 | +## Building for the Web (Browser) |
| 129 | + |
| 130 | +TBD |
| 131 | + |
| 132 | + |
| 133 | +## Building for iOS |
| 134 | +TBD |
0 commit comments