How do I fix java.lang.ClassNotFoundException: org.lwjgl.glfw.GLFW
6. Červenec 2024 v 01:10
I have not used Java in a while and thought I might try LWJGL with OpenGL and GLFW. I am using Apache Maven as a Build System. It lets me compile the program, but when I run it, it says:
Exception in thread "main" java.lang.NoClassDefFoundError: org.lwjgl/glfw/GLFW
at com.OpenGLTest.app.Main.main(Main.java:25)
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:525)
... 1 more
My code is:
// Main.java
package com.OpenGLTest.app;
import org.lwjgl.*;
import org.lwjgl.glfw.*;
import org.lwjgl.opengl.*;
import org.lwjgl.system.*;
import java.nio.*;
import static org.lwjgl.glfw.Callbacks.*;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryStack.*;
import static org.lwjgl.system.MemoryUtil.*;
public class Main {
private static long window;
private static final int WIDTH = 800;
private static final int HEIGHT = 600;
private static final String TITLE = "OpenGL Window";
public static void main(String[] args) {
// CHECK
if (!glfwInit()) {
System.err.println("ERROR: GLFW IS NOT INSTALLED");
System.exit(-1);
}
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_VISIBLE, 0);
glfwWindowHint(GLFW_RESIZABLE, 0);
window = glfwCreateWindow(WIDTH, HEIGHT, TITLE, NULL, NULL);
if (window == NULL) {
System.err.println("ERROR: FAILED TO CREATE GLFW WINDOW");
}
glfwMakeContextCurrent(window);
glfwShowWindow(window);
}
}
My LWJGL version is 3.3.3 My JRE is 17
I am sorry if the answer is obvious. Somehow the only kinda answer I found on the internet is http://forum.lwjgl.org/index.php?topic=6994.0:
https://stackoverflow.com/questions/34413/why-am-i-getting-a-noclassdeffounderror-in-java
How to solve this entirely depends on how you invoke the java command, whether you use an >IDE and which one you use, whether you use the Java 9+ Module System or the classpath and >whether you use a Java build system (like Maven, Gradle, Ant+Ivy).