Search code examples
javaeclipseopengllwjgljava-10

Can't import any referenced libraries from build path in eclipse


I'm trying to work my way through ThinMatrix's Open Gl Java tutorial. And... I'm stuck on video 1. I also worked through the short precursor video where he installed on the dependencies (Including lwjgl 2) in eclipse. Right now I just have the very start of the first class:

package renderEngine;
import org.lwjgl.opengl.Display; //Error is here
import org.lwjgl.opengl.DisplayMode; //And here
//Handle the window
public class DisplayManager {
    //Create a display
    public static void createDisplay() {
        Display.setDisplayMode(new DisplayMode());
    }
}

I receive the error, "The import org cannot be resolved". Even though I've added the files to the build path config and I've added the native path in there as well. I've looked at this similar question and effectively tried every proposed solution. I've also tried deleting the project and reinstalling the dependencies. Here is my file tree for reference:

enter image description here

I'd be highly grateful if you could show me what I've done wrong. Thanks so much.

Edit 1:

I've discovered something interesting concerning the line:

Display.setDisplayMode(new DisplayMode());

While both Display and DisplayMode are underlined in red because the import is not working above, one of the "quick fixes" that comes up (even if I delete the import statements) is:

Import 'Display' (org.lwjgl.opengl)

Clicking this writes the import statement at the top (if it isn't there) or brings the cursor to it (if it is there). It then throws the aforementioned error. This seems to indicate that it does actually recognize the fact that the libraries are there, but for some reason can't import them.

The plot thickens.

Edit 2:

To check whether the problem is specifically to do with compatibility with lwjgl2 I've tried importing a class from another library (a linear algebra library called "jblas") with:

import org.jblas.Info;

...but once again I receive the same error. I guess this indicates that the problem is with the way that I am adding the scripts to the build path, with the software itself or a combination thereof.

To clarify how I put things on the build path:

Right click project name -> click "build path" -> click "configure build path" -> click "libraries" -> click on eiether "module path" or "class path" (I've tried both) -> click "add jars" -> navigate to my "lib" folder -> go inside "jars" folder -> select all the jars -> click "apply and close".

Edit 3:

I can import the built-in packages and I can import packages that I've made.


Solution

  • EDIT: DON'T DO THE FOLLOWING: LOOK AT THE EDIT I downgraded my eclipse version to Oxygen, now I can import the packages without errors. Hopefully, this is remedied eventually so that I can move to the latest version of eclipse. Also, even in oxygen, it didn't work at first. I created a new project and reimported the various jars.

    Edit: I faced this problem again, in oxygen

    Fortunately this time I resolved it more quickly. I simply added the following snippet to my module-info.jar:

    requires org.lwjgl;
    

    Yep it was that simple.

    was probably the problem the first time as well. This second problem arose from a second project I decided to make. The last project didn't have a module-info.jar.

    That's why it allowed me to not write that line. Meanwhile, the original projects in eclipse 2018/19 did have the module-info.jar file and did have the problem. Maybe in Oxygen it just doesn't happen by default?