LWJGL / lwjgl3

LWJGL is a Java library that enables cross-platform access to popular native APIs useful in the development of graphics (OpenGL, Vulkan, bgfx), audio (OpenAL, Opus), parallel computing (OpenCL, CUDA) and XR (OpenVR, LibOVR, OpenXR) applications.
https://www.lwjgl.org
BSD 3-Clause "New" or "Revised" License
4.75k stars 635 forks source link

STBImage ClassNotFoundException #855

Closed Krausler closed 1 year ago

Krausler commented 1 year ago

Version

3.3.2 (nightly), 3.3.1

Platform

Windows x64

JDK

Oracle OpenJDK version 19.0.1

Module

STB

Bug description

So I found when running my LWJGL Vulkan application that is compiled as a jar file it throws a ClassNotFoundException and NoClassDefFoundError. When I start the application in my IDE (IntelliJ) it works alright but when i build the project and run it from the jar file it throws these two errors. I'm not really sure if this is caused by my application or by the LWJGL implementation.

This error occurs when I'm loading an image via STBImage.stbi_load. The weird thing is that this also occured in the IDE then it suddently stoped and only showed up when running the compiled jar. Again I don't know if this is an error in my application what possibly could be because I do get another errror before those 2 that have to do with method invokation. I will add the errors down below.

Stacktrace or crash log output

java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
        at java.base/java.lang.reflect.Method.invoke(Method.java:577)
        at dam.core.event.EventHandler.fireEvent(EventHandler.kt:78)
        at test.Main.key(Main.kt:85)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
        at java.base/java.lang.reflect.Method.invoke(Method.java:577)
        at dam.core.event.EventHandler.fireEvent(EventHandler.kt:78)
        at dam.core.window.listeners.input.KeyListener.keyListener(KeyListener.kt:25)
        at org.lwjgl.glfw.GLFWKeyCallbackI.callback(GLFWKeyCallbackI.java:44)
        at org.lwjgl.system.JNI.invokeV(Native Method)
        at org.lwjgl.glfw.GLFW.glfwPollEvents(GLFW.java:3403)
        at dam.core.window.Window.updateWindow(Window.kt:96)
        at dam.core.application.Application.applicationRun(Application.kt:67)
        at dam.Entry.main(Entry.kt:16)
Caused by: java.lang.NoClassDefFoundError: org/lwjgl/stb/STBImage
        at dam.renderer.FrontEndRenderer.loadTexture(FrontEndRenderer.kt:44)
        at dam.renderer.FrontEndRenderer.onDebug(FrontEndRenderer.kt:120)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
        ... 13 more
Caused by: java.lang.ClassNotFoundException: org.lwjgl.stb.STBImage
        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:521)
        ... 16 more
ws909 commented 1 year ago

If you use LWJGL modules from Maven, and not pre-configured from the website, did you add this module to the jar as well? I assume IntelliJ doesn't compile to the jar, and run that, when you're clicking IDEA's run button? IntelliJ may have automatically resolved the issue for its own build, but not for the jar.

Krausler commented 1 year ago

I configured the modules on the LWJGL website and copied the maven code into te pom.xml file and before I've used the STB module everything worked fine even the compiled jar file ran without any errors. And I forgot to say that this is a kotlin project.