I understand that this is a relatively common question, but I've followed the answers to so many of these at this point and none of them work.
I'm using Eclipse (on Mac now although I had the issue on Windows) and I want to learn the LWJGL which is a library for Java. I downloaded all the jars, and copied them into a lib folder:
then, as an example I added 3 of them to the project's build path, so that they appear in the referenced libraries section
Now, although I can literally see that org.lwjgl
for example is in my referenced libraries, I am always unable to use it in my code...
does anyone know why this keeps happening?
CodePudding user response:
You seem to be using a modularized Java application, that is, one that uses the Java 9 module system with its module path and not the pre-Java-Module-System classpath.
So you are going to have to declare a dependency in your project's module-info.java
as well, making it look something like:
module whatever.your.app.module.is {
requires org.lwjgl;
requires org.lwjgl.natives;
requires org.lwjgl.glfw;
requires org.lwjgl.glfw.natives;
requires org.lwjgl.opengl;
requires org.lwjgl.opengl.natives;
}
The important parts are the requires
declarations in your module-info.java
file, which you have to add.
Merely adding the LWJGL jar files to Eclipse's module path (as opposed to its classpath) will not make the classes available to your modularized Java application.
An alternative to a modularized Java application is one that does not use the Java Module System. In this case, you can simply delete your module-info.java
file and add LWJGL's jar files (including the ones with "natives" in their names) to Eclipse's build path classpath (as opposed to the "modulepath").