I am just starting to learn LWJGL3, but fot some reason, the imports don't work. I tried 2 methods of installing LWJGL3, first time I followed a video tutorial, second time I installed it how the official installation guide told me to (Guide). All of the JARs that come with LWJGL3 are included in the JRE System Library. The error appears as soon as I try to utilise glfw.
Code:
import static org.lwjgl.glfw.GLFW.*;
import org.lwjgl.glfw.GLFWVidMode;
public class Main {
public static void main(String[] args) {
if (!glfwInit()) {
throw new IllegalStateException("Failed to initialise GLFW");
}
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
long window = glfwCreateWindow(640, 480, "LWJGL Porgramme", glfwGetPrimaryMonitor(), 0);
if(window == 0) {
throw new IllegalStateException("Failed to create window");
}
GLFWVidMode videoMode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowPos(window, (videoMode.width() - 640) / 2, (videoMode.height() - 480)/ 2);
glfwShowWindow(window);
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
}
}
}
Error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/lwjgl/glfw/GLFW
at Main.main(Main.java:6)
Caused by: java.lang.ClassNotFoundException: org.lwjgl.glfw.GLFW
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 1 more
Edit: ClassLoader can't load the class, but I don't know why it can't load the class, since it is added in "external JARs". Image
This took way too long, but I got it to work. I installed LWJGL3 with Gradle, made a Gradle project and copied the Java source code to the Gradle project.