Difference between revisions of "Talk:Loading libraries and natives from path"

From Slick2D Wiki
Jump to: navigation, search
(Created page with " == Keep native libs in folders == When you download the LWJGL package the libraries are in folders. <br /> To keep the good structure and to avoid to just drop everything in...")
(No difference)

Revision as of 16:35, 17 November 2013

Keep native libs in folders

When you download the LWJGL package the libraries are in folders.
To keep the good structure and to avoid to just drop everything into one folder, I wrote a few lines of code.

The structure for my example is:

<YourDirectory>
  ├── libs
  │   ├── lwjgl.jar
  │   ├── slick.jar
  │   └── natives
  │       ├── freebsd
  │       ├── linux
  │       ├── macosx
  │       ├── solaris
  │       ├── windows
  └── YourProgram.jar

The following code will set the right native folder:

public static void main(final String[] args) {
// Set the native library for LWJGL
String operatingSystem = System.getProperty("os.name").toLowerCase();
	if (operatingSystem.startsWith("windows")) {
		operatingSystem = "windows";
	}
	else if (operatingSystem.startsWith("mac")) {
		operatingSystem = "macosx";
	}
	else if (operatingSystem.startsWith("linux")) {
		operatingSystem = "linux";
	}
	else if (operatingSystem.startsWith("solaris")) {
		operatingSystem = "solaris";
	}
	else if (operatingSystem.startsWith("free")) {
		operatingSystem = "freebsd";
	}
	System.setProperty("org.lwjgl.librarypath", new File("libs/natives/" + operatingSystem).getAbsolutePath());

	// Initialize AppGameContainer here...
}

--3Dx2Yz (talk) 16:35, 17 November 2013 (PST)