'glfwInit() is throwing an IllegalStateException error on initialization

I am trying to set up GLFW, but so far, I am getting stuck on the very first step, which is calling glfwInit(). My code is below:

import static org.lwjgl.glfw.GLFW.*;

public class Main {
    public static void main(String[] args)
    {
        if(!glfwInit())
        {
            throw new IllegalStateException("Failed to initialize GLFW");
        }
    }
}

I am getting this error: Exception in thread "main" java.lang.ExceptionInInitializerError at org.lwjgl.glfw.GLFW.glfwInit(GLFW.java:1046) at Main.main(Main.java:6) Caused by: java.lang.IllegalStateException: GLFW may only be used on the main thread and that thread must be the first thread in the process. Please run the JVM with -XstartOnFirstThread. This check may be disabled with Configuration.GLFW_CHECK_THREAD0. at org.lwjgl.glfw.EventLoop.<clinit>(EventLoop.java:30).

For reference, I am on a Mac, and am using eclipse, and have every single LWJGL jar file included in the project classpath.

Will running JVM with -XstartOnFirstThread like the warning says fix the issue? And if so, how do I do it?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source