简体   繁体   English

如何在 Eclipse 中设置 JVM 启动参数?

[英]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.我正在开发一个需要 LWJGL 的项目,我正在尝试启动并运行该项目,但在设置 JVM Launch 参数方面遇到了障碍。

The documentation for the LWJGL reads as follows: LWJGL 的文档如下:

Set the -Djava.library.path system property (as a JVM launch argument) to the folder containing your native files将 -Djava.library.path 系统属性(作为 JVM 启动参数)设置为包含本机文件的文件夹

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.我已经将 LWJGL jar 添加到 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.我已经做了一些查询来弄清楚如何设置 JVM Launch 参数,但我遗漏了一些明显的东西。 I'm new to build configurations with projects in Java.我是使用 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.此外,我的 lwjgl jar 位于我的项目文件夹中可能是重要的信息。

Right click the mouse -> Run Configurations... ->Arguments.then do as the following screenshot.右键单击鼠标 -> Run Configurations... ->Arguments.then 执行以下屏幕截图。

在此处输入图片说明

Hope that helped.希望有所帮助。

You can set system properties directly in your code so they work outside of eclipse.您可以直接在代码中设置系统属性,以便它们在 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).顺便说一句:你也可以设置org.lwjgl.librarypath ,它更具体(尽管这两个属性都可以工作)。

EDIT: As of 3.0.0b build 37 it is possible to set these properties at runtime with the new Configuration class.编辑:从 3.0.0b build 37 开始,可以在运行时使用新的Configuration类设置这些属性。

public class Main {
    final String PATH_TO_NATIVES = /*...*/;
    Configuration.LIBRARY_PATH.set(PATH_TO_NATIVES);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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