简体   繁体   中英

How to set a JVM launch argument in Eclipse?

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.

在此处输入图片说明

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

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

在此处输入图片说明

Hope that helped.

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM