Hot questions for Using Lightweight Java Game Library in jvm

Question:

I can't find documentation for the VM argument -XstartOnFirstThread. Seems necessary for me to run JOGL through LWJGL on my Mac. What does it mean? It seems to be that some process wants thread 0. Is this correct?

Please note: I have a run() method in my main class. It doesn't seem to be overriding anything and I'm not implementing runnable.

Example source code I'm running here: http://www.lwjgl.org/guide


Answer:

As of Java 1.7.0_u4, this option is documented in java -X on the Mac OSX platform.

The option causes the JVM to use thread 0 to start the application. Apparently this is necessary to get Mac OSX to run SWT and GWT apps properly. According to the Eclipse SWT FAQ, AWT and Swing apps use some undocumented magic to do this.

Question:

I'm working on a project that requires LWJGL and I'm trying to get the project up and running and have hit a road block in terms of getting the JVM Launch arguments set up.

The documentation for the LWJGL reads as follows:

Set the -Djava.library.path system property (as a JVM launch argument) to the folder containing your native files

The error I'm getting is:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
  at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857)
  at java.lang.Runtime.loadLibrary0(Runtime.java:870)
  at java.lang.System.loadLibrary(System.java:1119)
  at org.lwjgl.LWJGLUtil.loadLibrarySystem(LWJGLUtil.java:337)
  at org.lwjgl.Sys$1.run(Sys.java:36)
  at java.security.AccessController.doPrivileged(Native Method)
  at org.lwjgl.Sys.<clinit>(Sys.java:33)
  at HelloWorld.run(HelloWorld.java:24)
  at HelloWorld.main(HelloWorld.java:114)

I've already added the LWJGL jar into the Properties -> Java Build Path -> Libraries.

I've done some queries to figure out how to set JVM Launch arguments, and am missing something clearly obvious. I'm new to build configurations with projects in Java. Any ideas? Thx.

Update

After some helpful answers, I've added a system variable into my run configurations and am still getting the same error. Here is a screenshot of my Run Configurations.

Also, it may be important info that my lwjgl jar is located in my Project folder.


Answer:

You can set system properties directly in your code so they work outside of eclipse.

public class Main {
    static {
        final String PATH_TO_NATIVES = /*...*/;
        System.setProperty("java.library.path", PATH_TO_NATIVES);
    }
}

You should do this before any other actions, so put it inside a static block in your main class (like in the code above) or at the start of your main method.

By the way: You can also set org.lwjgl.librarypath instead, which is more specific (although both properties will work).

EDIT: As of 3.0.0b build 37 it is possible to set these properties at runtime with the new Configuration class.

public class Main {
    final String PATH_TO_NATIVES = /*...*/;
    Configuration.LIBRARY_PATH.set(PATH_TO_NATIVES);
}

Question:

I currently have a jar that needs the -Djava.library.path to be set for LWJGL on launch or it will throw an UnsatisfiedLinkError. To negate this problem, I have launched the jar through CMD with that VM argument using a batch file (Windows).

My question is - is there any way to do this natively in the jar without requiring some kind of launcher?


Answer:

You can set the properties inside your program. Use either

System.setProperty("org.lwjgl.librarypath", "path/to/natives");

or

Configuration.LIBRARY_PATH.set("path/to/natives");

at the start of your main method.