Installation
JOID ships as jars attached to each GitHub release; it is not published to a Maven repository. This page adds one backend jar to a Gradle project, declares the libraries next to it, and checks that Gradle compiles against it.
Prerequisites
- A JDK 8 or later, and Gradle 6.4 or later.
- A machine that meets the prerequisites of your backend. If you do not know which backend to pick, take LWJGL 3: Choosing a backend compares the three.
1. Download the backend jar
Section titled “1. Download the backend jar”Download from the release the jar of your backend, in its -dev flavor while you develop:
| Jar | Backend |
|---|---|
joid-backend-lwjgl3-8.0.0-dev.jar | OpenGL through LWJGL 3 and GLFW |
joid-backend-vulkan-8.0.0-dev.jar | Vulkan through LWJGL 3 and GLFW |
joid-backend-lwjgl2-8.0.0-dev.jar | OpenGL through LWJGL 2 |
Put it in a libs/ folder at the root of your project.
A backend jar holds the JOID core and the libraries that JOID uses for images, SVG, WebP, video and JSON.
All but the video libraries, and JNA in the LWJGL 2 jar, are relocated under dev.joid.shaded, so that they never clash with the versions your application uses.
Put exactly one backend jar on each classpath: two backend jars hold the same classes and break each other.
The release also holds two optional tools, each a plain jar next to your backend jar:
| Jar | Use it to |
|---|---|
joid-tool-testkit-8.0.0.jar | Render your UIs in JUnit 4 tests (Testing your UIs) |
joid-tool-msdf-8.0.0.jar | Generate the atlases of your fonts before you ship (Custom fonts and MSDF) |
2. Declare the libraries
Section titled “2. Declare the libraries”Next to the backend jar, a JOID application declares only the LWJGL modules of its backend, with their natives.
Write this build.gradle, with the block of your backend:
plugins { id 'java' id 'application'}
java { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8}
repositories { mavenCentral()}
def lwjglVersion = '3.3.4'def os = System.getProperty('os.name').toLowerCase()def arm = System.getProperty('os.arch').startsWith('aarch64')def lwjglNatives = arm ? 'natives-linux-arm64' : 'natives-linux'if (os.contains('win')) { lwjglNatives = 'natives-windows'} else if (os.contains('mac')) { lwjglNatives = arm ? 'natives-macos-arm64' : 'natives-macos'}
dependencies { implementation files('libs/joid-backend-lwjgl3-8.0.0-dev.jar')
['lwjgl', 'lwjgl-glfw', 'lwjgl-openal', 'lwjgl-opengl'].each { module -> implementation "org.lwjgl:${module}:${lwjglVersion}" runtimeOnly "org.lwjgl:${module}:${lwjglVersion}:${lwjglNatives}" }}
application { mainClass = 'com.example.start.VersionCheck' if (os.contains('mac')) { applicationDefaultJvmArgs = ['-XstartOnFirstThread'] }}plugins { id 'java' id 'application'}
java { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8}
repositories { mavenCentral()}
def lwjglVersion = '3.3.4'def os = System.getProperty('os.name').toLowerCase()def arm = System.getProperty('os.arch').startsWith('aarch64')def lwjglNatives = arm ? 'natives-linux-arm64' : 'natives-linux'if (os.contains('win')) { lwjglNatives = 'natives-windows'} else if (os.contains('mac')) { lwjglNatives = arm ? 'natives-macos-arm64' : 'natives-macos'}
dependencies { implementation files('libs/joid-backend-vulkan-8.0.0-dev.jar')
['lwjgl', 'lwjgl-glfw', 'lwjgl-openal', 'lwjgl-shaderc'].each { module -> implementation "org.lwjgl:${module}:${lwjglVersion}" runtimeOnly "org.lwjgl:${module}:${lwjglVersion}:${lwjglNatives}" }
implementation "org.lwjgl:lwjgl-vulkan:${lwjglVersion}" if (os.contains('mac')) { runtimeOnly "org.lwjgl:lwjgl-vulkan:${lwjglVersion}:${lwjglNatives}" }}
application { mainClass = 'com.example.start.VersionCheck' if (os.contains('mac')) { applicationDefaultJvmArgs = ['-XstartOnFirstThread'] }}LWJGL ships Vulkan natives for macOS only: on Windows and Linux, the Vulkan driver of the machine provides them.
plugins { id 'java' id 'application'}
java { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8}
repositories { mavenCentral()}
dependencies { implementation files('libs/joid-backend-lwjgl2-8.0.0-dev.jar')
implementation 'org.lwjgl.lwjgl:lwjgl:2.9.1'}
application { mainClass = 'com.example.start.VersionCheck'}The LWJGL 2 natives of Windows, Linux and macOS are inside the backend jar, and Lwjgl2Natives.install extracts them (Choosing a backend).
The jar also embeds JNA under its own package, com.sun.jna: if your application declares JNA too, keep a single copy on the classpath.
The natives classifier is the one of the machine that builds.
To package for several systems, add a runtimeOnly line for each classifier you ship.
3. Check the installation
Section titled “3. Check the installation”Create src/main/java/com/example/start/VersionCheck.java:
package com.example.start;
import dev.joid.lib.JOID;
public final class VersionCheck {
private VersionCheck() {}
public static void main(final String[] arguments) { System.out.println("JOID " + JOID.VERSION); }
}Run gradle run.
Check: the console prints JOID 8.0.0.
Gradle finds the backend jar and compiles against it.
The natives load only once JOID draws: the Quick Start checks them when it opens a first window.
Choose the dev or the prod jar
Section titled “Choose the dev or the prod jar”Every backend jar comes in two flavors.
Develop with -dev, and ship -prod:
| Flavor | Holds | Use it |
|---|---|---|
-dev | Everything your application needs, plus the dev tools: the inspector, the reload and the hot reload of a UI, the profiler, the dev warnings, a font for those tools, and the snapshot backends of the testkit | While you write and test your application |
-prod | Everything your application needs, nothing else | In the application you ship |
The jar on the classpath decides the mode, with no code to write. When the backend registers, JOID prints one line that tells which flavor runs, and where it keeps its files:
[JOID] 8.0.0 loaded in dev mode, data in C:\Games\Starfall\joid, cache in C:\Users\me\AppData\Local\joidWith the prod jar, the line reads [JOID] 8.0.0 loaded, data in …, cache in …, without in dev mode.
Where JOID stores files explains the two folders.
Give the application and the tests their own jar
Section titled “Give the application and the tests their own jar”Once you write screen tests or ship the application, declare each flavor in a configuration of its own.
Replace the implementation files(...) line of step 2 with this block:
configurations { joidProd joidDev compileClasspath.extendsFrom joidProd runtimeClasspath.extendsFrom joidProd testCompileClasspath.extendsFrom joidDev testRuntimeClasspath.extendsFrom joidDev}
dependencies { joidProd files('libs/joid-backend-lwjgl3-8.0.0-prod.jar') joidDev files('libs/joid-backend-lwjgl3-8.0.0-dev.jar')
testImplementation files('libs/joid-tool-testkit-8.0.0.jar') testImplementation 'junit:junit:4.13.2'}
tasks.named('run') { classpath = classpath - configurations.joidProd + configurations.joidDev}- The application compiles against the prod jar, and
gradle distZippacks the prod jar alone. - The tests compile and run on the dev jar alone, the flavor that holds the snapshot backends of the testkit.
gradle runswaps the prod jar for the dev jar, so the dev tools stay on while you develop.
Each classpath holds one backend jar.
With another backend, change the names of the two jars.
Ship your application lists what changes for the user when the application runs on -prod.
Play videos without network access
Section titled “Play videos without network access”JOID decodes videos with FFmpeg, whose native libraries the backend jar does not hold. By default, the first video downloads those of the running system into the cache folder (Images and media).
For a machine without network access, put them on the classpath instead, one line per system you ship:
dependencies { runtimeOnly('org.bytedeco:ffmpeg:6.0-1.5.9:windows-x86_64') { transitive = false } runtimeOnly('org.bytedeco:ffmpeg:6.0-1.5.9:linux-x86_64') { transitive = false } runtimeOnly('org.bytedeco:ffmpeg:6.0-1.5.9:macosx-x86_64') { transitive = false } runtimeOnly('org.bytedeco:ffmpeg:6.0-1.5.9:macosx-arm64') { transitive = false }}The version is the one that JOID embeds, so keep 6.0-1.5.9 exactly; transitive = false keeps out a second copy of JavaCPP, which the backend jar already holds.
When the classpath holds the natives of the running system, JOID downloads nothing and writes nothing into the cache folder for them.
Other build tools
Section titled “Other build tools”With Maven, install the jar in your local repository once, then declare it with the LWJGL modules of step 2:
mvn install:install-file \ -Dfile=libs/joid-backend-lwjgl3-8.0.0-dev.jar \ -DgroupId=dev.joid \ -DartifactId=joid-backend-lwjgl3 \ -Dversion=8.0.0 \ -Dclassifier=dev \ -Dpackaging=jarAny other build tool works the same way: the backend jar, and the LWJGL modules of the backend with their natives.
If it does not work
Section titled “If it does not work”Step 3 fails on the first two symptoms below. The others show when JOID draws for the first time, in the Quick Start.
package dev.joid.lib does not exist: Gradle finds no backend jar; check that the jar is inlibs/and thatfiles(...)names it exactly.Could not find or load main class: themainClassof theapplicationblock does not namecom.example.start.VersionCheck.NoClassDefFoundError: org/lwjgl/...,UnsatisfiedLinkErrororFailed to locate library: an LWJGL module of step 2 is missing, or its natives are missing or for another system; check theruntimeOnlylines and the classifier.- The JVM stops on macOS with a thread error: start it with
-XstartOnFirstThread, as theapplicationblock does. NoSuchMethodErrororClassCastExceptioninsidedev.joid: two backend jars are on one classpath; keep one per classpath.
