1

I'm working on a project that requires LWJGL and I'm trying to get the project up and running and have hit a road block in terms of getting the JVM Launch arguments set up.

The documentation for the LWJGL reads as follows:

Set the -Djava.library.path system property (as a JVM launch argument) to the folder containing your native files

The error I'm getting is:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
  at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857)
  at java.lang.Runtime.loadLibrary0(Runtime.java:870)
  at java.lang.System.loadLibrary(System.java:1119)
  at org.lwjgl.LWJGLUtil.loadLibrarySystem(LWJGLUtil.java:337)
  at org.lwjgl.Sys$1.run(Sys.java:36)
  at java.security.AccessController.doPrivileged(Native Method)
  at org.lwjgl.Sys.<clinit>(Sys.java:33)
  at HelloWorld.run(HelloWorld.java:24)
  at HelloWorld.main(HelloWorld.java:114)

I've already added the LWJGL jar into the Properties -> Java Build Path -> Libraries.

I've done some queries to figure out how to set JVM Launch arguments, and am missing something clearly obvious. I'm new to build configurations with projects in Java. Any ideas? Thx.

Update

After some helpful answers, I've added a system variable into my run configurations and am still getting the same error. Here is a screenshot of my Run Configurations.

enter image description here

Also, it may be important info that my lwjgl jar is located in my Project folder.

Unome
  • 6,750
  • 7
  • 45
  • 87
  • possible dublicate: http://stackoverflow.com/questions/19344914/getting-java-lang-unsatisfiedlinkerror-no-lwjgl-in-java-library-path – soorapadman Sep 15 '15 at 05:15

2 Answers2

3

Right click the mouse -> Run Configurations... ->Arguments.then do as the following screenshot.

enter image description here

Hope that helped.

Javy
  • 944
  • 5
  • 9
  • That did (+1), though I'm still getting the error, I've updated my post. – Unome Sep 15 '15 at 14:08
  • Upon further search, i had not added the native files to the project, I had only added the JAR. Upon adding the jar this solution worked great. Thanks! – Unome Sep 15 '15 at 14:30
3

You can set system properties directly in your code so they work outside of eclipse.

public class Main {
    static {
        final String PATH_TO_NATIVES = /*...*/;
        System.setProperty("java.library.path", PATH_TO_NATIVES);
    }
}

You should do this before any other actions, so put it inside a static block in your main class (like in the code above) or at the start of your main method.

By the way: You can also set org.lwjgl.librarypath instead, which is more specific (although both properties will work).

EDIT: As of 3.0.0b build 37 it is possible to set these properties at runtime with the new Configuration class.

public class Main {
    final String PATH_TO_NATIVES = /*...*/;
    Configuration.LIBRARY_PATH.set(PATH_TO_NATIVES);
}
javac
  • 2,431
  • 4
  • 17
  • 26
  • +1. Both answers are correct, but this one allows you to choose different natives per operating system, allowing compatibility for more than just windows. Also it works outside of Eclipse. – Joehot200 Sep 15 '15 at 10:58
  • I'm trying to implement this method and have a couple questions. First, I set the code you provided in a static block at the top of my code, but its still giving there error. I've tried both just the folder "TestProject" and the actual path to the jar. I'm assuming that the native files I'm trying to give a path to, is the lwjgl jar? Any ideas what I'm doing wrong? – Unome Sep 15 '15 at 13:59
  • @Unome You have to set the path to the folder containing the files with extensions like `.dll`, `.so` or `.dylib`. In the zip you downloaded there should be a folder called `native` which contains these files. Note that in LWJGL 2 there are several subfolders so you have to choose the correct one for your operating system (there it helps to be able to programmatically set the system property). – javac Sep 15 '15 at 15:38