Sk4llsRPG Sk4llsRPG - 1 year ago 124
Java Question

LWJGL Automatic Native Picker

In LWJGL, (I am on a mac), I am making a program in it but as I debug/run my code, it requires the LWJGL OS X natives to run.

Same goes for Windows, Linux or anything else but I want it to be a little bit like the game Minecraft which was made in LWJGL.

You start the game and it automatically picks your operating systems natives.

Is there a way I can do this so I dont have to switch around manually on different operating systems?

Please share your source if you know!!

Answer Source

Have a look at this:

It says that you can set the path to your natives by calling the following at the beginning of your main method:

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

By doing some OS detection you should be able to load the right natives, like so:

if (System.getProperty("").contains("Windows")) {
    // Windows
    System.setProperty("org.lwjgl.librarypath", new File("lwjglFolderLocation/native/windows").getAbsolutePath());
} else if (System.getProperty("").contains("Mac")) {
    // Mac OS X
    System.setProperty("org.lwjgl.librarypath", new File("lwjglFolderLocation/native/macosx").getAbsolutePath());
} else if (System.getProperty("").contains("Linux")) {
    // Linux
    System.setProperty("org.lwjgl.librarypath", new File("lwjglFolderLocation/native/linux").getAbsolutePath());
} else if (System.getProperty("").contains("Sun")) {
    // SunOS (Solaris)
    System.setProperty("org.lwjgl.librarypath", new File("lwjglFolderLocation/native/solaris").getAbsolutePath());
} else {
    throw new RuntimeException("Your OS is not supported");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download