Skip to content

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

Download from the release the jar of your backend, in its -dev flavor while you develop:

JarBackend
joid-backend-lwjgl3-8.0.0-dev.jarOpenGL through LWJGL 3 and GLFW
joid-backend-vulkan-8.0.0-dev.jarVulkan through LWJGL 3 and GLFW
joid-backend-lwjgl2-8.0.0-dev.jarOpenGL 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:

JarUse it to
joid-tool-testkit-8.0.0.jarRender your UIs in JUnit 4 tests (Testing your UIs)
joid-tool-msdf-8.0.0.jarGenerate the atlases of your fonts before you ship (Custom fonts and MSDF)

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']
}
}

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.

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.

Every backend jar comes in two flavors. Develop with -dev, and ship -prod:

FlavorHoldsUse it
-devEverything 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 testkitWhile you write and test your application
-prodEverything your application needs, nothing elseIn 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\joid

With 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 distZip packs 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 run swaps 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.

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.

With Maven, install the jar in your local repository once, then declare it with the LWJGL modules of step 2:

Terminal window
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=jar

Any other build tool works the same way: the backend jar, and the LWJGL modules of the backend with their natives.

Step 3 fails on the first two symptoms below. The others show when JOID draws for the first time, in the Quick Start.

  1. package dev.joid.lib does not exist: Gradle finds no backend jar; check that the jar is in libs/ and that files(...) names it exactly.
  2. Could not find or load main class: the mainClass of the application block does not name com.example.start.VersionCheck.
  3. NoClassDefFoundError: org/lwjgl/..., UnsatisfiedLinkError or Failed to locate library: an LWJGL module of step 2 is missing, or its natives are missing or for another system; check the runtimeOnly lines and the classifier.
  4. The JVM stops on macOS with a thread error: start it with -XstartOnFirstThread, as the application block does.
  5. NoSuchMethodError or ClassCastException inside dev.joid: two backend jars are on one classpath; keep one per classpath.

Report a problem with this page