LibGDX Native Libraries

This is probably a dumb question, but it’s been bugging me for a while.

I can successfully deploy a LWJGL game by adding its natives to my native library path when I run the jar using the -Djava.library.path argument. That works great.

I can also successfully deploy a libGDX game just be exporting a runnable jar. That also works great. My question is… why does that work? Why don’t I have to set the native library path when I run the libGDX jar? LibGDX is built on top of LWJGL, so shouldn’t it require the same native libraries? Does libGDX extract them automagically?

Again, I know how to get both LWJGL and libGDX working, my only question is why I don’t seem to have to set the native library path with libGDX, even though LWJGL requires it. I suspect some witchcraft going on, and I’m just curious what that witchcraft is.

(Or maybe my assumptions are invalid and my runnable jar approach has only worked coincidentally and isn’t what I should actually be doing?)

System.setProperty("org.lwjgl.librarypath", libraryPath);

at runtime while having the natives extracted to “libraryPath” is useful.

This is not exactly what you asked but where it will end up.

Are you saying that’s what libGDX does?

I use SvgExe to deploy LWJGL with self-extracting natives, so I don’t have to worry about setting it myself. Does libGDX use the code you posted and some internal automagic self-extracting logic?

This article from FromMyPlayGround says how to do it.

Sorry, but that isn’t my question. I understand how to load native libraries. I do that with LWJGL, and in fact wrote a tool that handles it for Processing.

My question is, why don’t I have to do that with libGDX? Every libGDX game I’ve made works fine as a runnable jar without setting the native library location. Again, I’m not asking how to set the native library location. I’m asking why I don’t seem to have to with libGDX.

Am I just getting lucky and not hitting any native code (seems unlikely since I’m using OpenGL), or does libGDX have some kind of internal mechanism for extracting its own native libraries?

[quote]or does libGDX have some kind of internal mechanism for extracting its own native libraries?
[/quote]
Probably, our posts were about how.
Anything else?

As you guessed yourself, the libGDX backend jars contain the natives. On startup the framework checks if there is already a folder containing the natives where it expect it to be, if not the folder is created and the natives are extracted from the right backend jar. After that the system properties of lwjgl and other native libs are set and your game starts.

Probably, our posts were about how.
Anything else?
[/quote]
I meant no disrespect, but I understand how it would work. The tool I wrote for Processing does exactly that (well, similar to that anyway), so I wasn’t asking about how it might be done. I couldn’t find any easily digestible (I suppose I could traipse through the source) information on it though, so I figured I’d ask here.

Again, I meant no disrespect and I didn’t mean to sound dismissive of your answers. I was just looking for specifics on whether libGDX in fact did some automagic preprocessing, not how it might be done. Mostly I was making sure I was deploying libGDX correctly and not missing a step.

Thanks for the replies!

Thanks! This is exactly what I was looking for!

The more I learn about libGDX, the more clever I think it is…

You may want to check this class from the LibGdx source. LwjglNativesLoader

Awesome, thanks again. This is exactly what I was curious about. I appreciate it.