0

I'm trying to create a window in Kotlin using the LWJGL3 library. The code compiles, IntelliJ sees no issue. However when I run it expecting it to return either a 0 or a 1 to be printed out, I instead get the error message:

Exception in thread "main" java.lang.NoClassDefFoundError: org/lwjgl/glfw/GLFW
    at azure.beorn.MainKt.init(Main.kt:28)
    at azure.beorn.MainKt.main(Main.kt:21)
    at azure.beorn.MainKt.main(Main.kt)
Caused by: java.lang.ClassNotFoundException: org.lwjgl.glfw.GLFW
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
    ... 3 more

so far, I've tried adding another dependency to see if it was an issue with my LWJGL setup or with my Kotlin setup as a whole. Which showed that it's an issue with how I have LWJGL setup.

I have also added runtime blocks into my build.gradle.kts, which had no effect on the final outcome

dependencies {
    implementation(platform("org.lwjgl:lwjgl-bom:$lwjglVersion"))

    implementation("org.lwjgl:lwjgl")
    implementation("org.lwjgl:lwjgl-assimp")
    implementation("org.lwjgl:lwjgl-glfw")
    implementation("org.lwjgl:lwjgl-openal")
    implementation("org.lwjgl:lwjgl-stb")
    implementation("org.lwjgl:lwjgl-vulkan")

    runtimeOnly("org.lwjgl:lwjgl::$lwjglNatives")
    runtimeOnly("org.lwjgl:lwjgl-assimp::$lwjglNatives")
    runtimeOnly("org.lwjgl:lwjgl-glfw::$lwjglNatives")
    runtimeOnly("org.lwjgl:lwjgl-openal::$lwjglNatives")
    runtimeOnly("org.lwjgl:lwjgl-stb::$lwjglNatives")
    if (lwjglNatives == "natives-macos") runtimeOnly("org.lwjgl:lwjgl-vulkan::$lwjglNatives")

    implementation("org.joml:joml:$jomlVersion")
    implementation("io.github.quillraven.fleks:Fleks:2.12")
}

my current code is

package azure.beorn

import com.github.quillraven.fleks.configureWorld
import org.lwjgl.*;
import org.lwjgl.glfw.*;
import org.lwjgl.vulkan.*;
import org.lwjgl.system.*;


import org.lwjgl.glfw.GLFW.*

import org.lwjgl.glfw.Callbacks.*
import org.lwjgl.glfw.GLFW.*
import org.lwjgl.system.MemoryStack.*
import org.lwjgl.system.MemoryUtil.*

fun main() {

    val window = init()
    val world = configureWorld{};
    loop(window)
}

fun init(): Long{
    //GLFWErrorCallback.createPrint(System.err).set()
    if(!glfwInit())
        return 1;
    return 0
}

fun loop(window: Long){

}

and my full build.gradle.kts is

plugins {
    kotlin("jvm") version "2.2.10"
}

group = "azure.beorn"
version = "1.0-SNAPSHOT"


val lwjglVersion = "3.3.6"
val jomlVersion = "1.10.8"


val lwjglNatives = Pair(
    System.getProperty("os.name")!!,
    System.getProperty("os.arch")!!
).let { (name, arch) ->
    when {
        arrayOf("Linux", "SunOS", "Unit").any { name.startsWith(it) } ->
            if (arrayOf("arm", "aarch64").any { arch.startsWith(it) })
                "natives-linux${if (arch.contains("64") || arch.startsWith("armv8")) "-arm64" else "-arm32"}"
            else if (arch.startsWith("ppc"))
                "natives-linux-ppc64le"
            else if (arch.startsWith("riscv"))
                "natives-linux-riscv64"
            else
                "natives-linux"
        arrayOf("Mac OS X", "Darwin").any { name.startsWith(it) }     ->
            "natives-macos"
        arrayOf("Windows").any { name.startsWith(it) }                ->
            "natives-windows"
        else                                                                            ->
            throw Error("Unrecognized or unsupported platform. Please set \"lwjglNatives\" manually")
    }
}


repositories {
    mavenCentral()
}

dependencies {
    implementation(platform("org.lwjgl:lwjgl-bom:$lwjglVersion"))

    implementation("org.lwjgl:lwjgl")
    implementation("org.lwjgl:lwjgl-assimp")
    implementation("org.lwjgl:lwjgl-glfw")
    implementation("org.lwjgl:lwjgl-openal")
    implementation("org.lwjgl:lwjgl-stb")
    implementation("org.lwjgl:lwjgl-vulkan")

    runtimeOnly("org.lwjgl:lwjgl::$lwjglNatives")
    runtimeOnly("org.lwjgl:lwjgl-assimp::$lwjglNatives")
    runtimeOnly("org.lwjgl:lwjgl-glfw::$lwjglNatives")
    runtimeOnly("org.lwjgl:lwjgl-openal::$lwjglNatives")
    runtimeOnly("org.lwjgl:lwjgl-stb::$lwjglNatives")
    if (lwjglNatives == "natives-macos") runtimeOnly("org.lwjgl:lwjgl-vulkan::$lwjglNatives")

    implementation("org.joml:joml:$jomlVersion")
    implementation("io.github.quillraven.fleks:Fleks:2.12")
}

1 Answer 1

0

I switched from Kotlin build to Groovy build at that seems to have fixed the issue

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.