Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Okay, so I know I need to set the path to the native files. I can do this in Eclipse, by going to the VM arguments and using -Djava.library.path=, but when I export, it says that the VM arguments aren't kept after exporting, but it can be set in the console while running it. I am running Mac OS X. How do I set that using Terminal?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

It should be exactly the same, just provide -Djava.library.path="your_path" to java when you run it:

java -Djava.library.path="your_path" -classpath "your_classpath" your.main.Class
share|improve this answer
    
Wouldja look at that. If only my 30 minutes of Google searching could have just said that. Thanks! –  Brandon oubiub Jun 24 '11 at 2:55

I just wrote a nifty way to solve this problem, without needing to define the library beforehand. Which is more useful when you actually deploy your game. Basically it goes like this:

  1. Detect OS and architecture
  2. Copy LWJGL native binaries from inside your .jar file to game directory
  3. Dynamically set library path for Java to the natives folder in your game directory
  4. Continue with the rest of your game loading

This needs to happen first thing. So at the beginning of your main function goes:

loadNatives(getPlatform());

Then you have your getPlatform() function (step 1 from above), you can get the OS details like so:

String OS_Arch = System.getProperty("os.arch").toLowerCase();
String OS_Name = System.getProperty("os.name").toLowerCase();

Use those to return an enum that defines your OS and architecture, i.e. Win_X86.

Then you load your natives that are packaged in your .jar file (step 2 from above). Depending on the OS and architecture you'll load certain files from the LWJGL native binaries. For example Win_X86 would be something like:

String path = Main.class.getProtectionDomain().getCodeSource().getLocation().getPath();
copyFileFromJar("/assets/native/windows/jinput-raw.dll",
  path + "/native/jinput-raw.dll");
copyFileFromJar("/assets/native/windows/jinput-dx8.dll",
  path + "/native/jinput-dx8.dll");
copyFileFromJar("/assets/native/windows/lwjgl.dll",
  path + "/native/lwjgl64.dll");
copyFileFromJar("/assets/native/windows/OpenAL32.dll",
  path + "/native/OpenAL32.dll");

Where copyFileFromJar() just makes an input stream and an output stream, then streams until it can stream no more. The input stream is from the native file in your .jar and the output is the destination file (which probably needs to be created first!)

Finally, tell Java about this new library resource (Step 3 from above):

System.setProperty("java.library.path", path + "native/");
Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
fieldSysPath.setAccessible(true);
fieldSysPath.set(null, null);
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.