[LWJGL3] load natives next-to-jar

Hiah!

With lwjgl2 I always liked to load my natives from a folder next to the jar file; it just seems nicer that way than having to specify a command-line. To do this, I wrote:

System.setProperty("java.library.path", new File("Resources/native").getAbsolutePath());

In my main method.

This, however, does not seem to work with LWJGL3. I’ve googled it a bit, and no one seems to have an issue.

I did, however, find this:

static {
	System.setProperty("java.library.path", new File("natives").toPath().toString());
}

Though quite similar to my code, it also does not work.

Is there any way to load LWJGL3 natives from a folder next to the jar file?

LWJGL3 has a new feature (nightly builds) in that you can just put the natives in a jar file and add that jar to the classpath (or even put them in the lwjgl.jar if you don’t want a seperate jar). LWJGL3 will automatically detect them and load them from there (they should be in the root of the jar/zip and not in a subfolder).

Alternatively if you still want to do it the old way you can try

System.setProperty("org.lwjgl.librarypath", new File("Resources/native").getAbsolutePath());

There is also the new org.lwjgl.system.Configuration class for setting LWJGL variables at run time, the path to the natives can be set at runtime as follows:

Configuration.LIBRARY_PATH.set("libs");

Hey orange451,

[quote=“orange451,post:1,topic:55714”]
The above could not have worked with LWJGL 2 either. The “java.library.path” property is read only once at JVM startup and cached. Effectively you cannot set it at runtime, without some hackery at least. That’s why LWJGL 2 supported the “org.lwjgl.librarypath” property and LWJGL 3 does too.

Like kappa mentioned, LWJGL 3 now also has the Configuration class. It is just a nicer way to configure LWJGL programmatically, with appropriate documentation and without hard to remember strings.

Hi

Does LWJGL 3 extract the native libraries from the JAR and copy them into a temporary directory before loading them?

[quote=“gouessej,post:4,topic:55714”]
Yes. The code for this was contributed by @badlogicgames.

There are a few corner cases to handle, we have had a similar mechanism in JogAmp for several years now. Some virus scanners still get crazy when we copy the native libraries anywhere.

That’s why I don’t generally recommend it. I added it to LWJGL mostly as a convenience for developers wanting to try the library via Maven/Gradle. Makes the first experience much nicer.

Well… It did :x
I’ve been using that for over a year now, and I’ve tested it on maybe 10 computers.

Anyways, thank you for the help!