Java 尝试运行 LWJGL“Hello World”时如何解决此 JNI 错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28922512/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 07:01:58  来源:igfitidea点击:

How to resolve this JNI error when trying to run LWJGL "Hello World"?

javaclasspathlwjgl

提问by yoonsi

I'm trying to run the sample "Hello World" from the LWJGL website

我正在尝试从 LWJGL 网站运行示例“Hello World”

From this link: LWJGL "Getting Started"

来自此链接:LWJGL“入门”

I'm trying to do this via the command line, just so I understand the "behind the scenes" a bit better.

我试图通过命令行来做到这一点,只是为了让我更好地理解“幕后”。

I've managed to compile without any errors, but when I try to run the program I'm getting this error:

我设法编译没有任何错误,但是当我尝试运行该程序时,出现此错误:

C:\JavaProjects\LearningLWJGL>java -classpath .;./lib/*.jar -Djava.library.path=C:\Windows\System32 HelloWorld
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/lwjgl/glfw/GLFWKeyCallback
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
    at java.lang.Class.privateGetMethodRecursive(Unknown Source)
    at java.lang.Class.getMethod0(Unknown Source)
    at java.lang.Class.getMethod(Unknown Source)
    at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.lwjgl.glfw.GLFWKeyCallback
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 7 more

Any ideas?

有任何想法吗?

采纳答案by user207421

A CLASSPATH entry is either a directory at the head of a package hierarchy of .class files, or a .jar file. If you're expecting ./libto include all the .jar files in that directory, it won't. You have to name them explicitly.

CLASSPATH 条目要么是位于 .class 文件包层次结构头部的目录,要么是 .jar 文件。如果您希望./lib在该目录中包含所有 .jar 文件,则不会。您必须明确命名它们。

回答by Vlado Lesko

I had same issue using different dependancy what helped me is to set scope to compile.

我在使用不同的依赖时遇到了同样的问题,帮助我的是设置编译范围。

<dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
        <scope>compile</scope>
    </dependency>