Java-库路径错误 [英] Java - Library path error
问题描述
我正在尝试开始我的Java游戏,但是我在使用Java命令行时遇到了一些麻烦:
I'm trying to start my java game but I have some troubles with the java command line:
这是我输入的内容:
C:\>java -Djava.library.path=%cd%\lib -jar game.jar
这就是我得到的:
Exception in thread "main" java.lang.NoClassDefFoundError: org/lwjgl/LWJGLException
at com.game.Main.main(Main.java:7)
Caused by: java.lang.ClassNotFoundException: org.lwjgl.LWJGLException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
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)
... 1 more
我可以使用Eclipse(以Java应用程序运行)开始游戏,但是在菜单后出现以下错误:
I can start my game with Eclipse (With Run as Java Application) but after the menu I got the following error:
Exception in thread "Thread-5" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at org.lwjgl.Sys$1.run(Sys.java:72)
at java.security.AccessController.doPrivileged(Native Method)
at org.lwjgl.Sys.doLoadLibrary(Sys.java:65)
at org.lwjgl.Sys.loadLibrary(Sys.java:81)
at org.lwjgl.Sys.<clinit>(Sys.java:98)
at org.lwjgl.opengl.Display.<clinit>(Display.java:129)
at com.game.displaygui.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
lwjgl.jar
已放入文件夹\lib
.
你能解释一下我吗?
谢谢.
推荐答案
这是因为lwjgl库由两个组件组成:
This because lwjgl library is made by two components:
- 包含Java代码的 .jar 文件
- 和本机二进制库(根据您的操作系统可以是 .so 或 .dll 或 .dylib )
- the .jar file which contains Java code
- and the native binary library (which can be .so or .dll or .dylib according to your OS)
您遇到的第一个错误是因为您正在设置库路径,该路径应包含 native 库,但它确实包含.jar.因此,您得到一个java.lang.NoClassDefFoundError
,因为您应该将库路径设置为包含本机库的文件夹,或者将类路径设置为包含实际的 lwjgl.jar 文件.
The first error you are getting is because you are setting the library path, that should contain the native library, but it does contain the .jar. So you get a java.lang.NoClassDefFoundError
because you should set either the library path to the folder that contains native library, either the classpath to contain the real lwjgl.jar file.
您在Eclipse中遇到的第二个错误是一个连续的步骤:您的类路径包含jar库,但是它找不到附加到其的本机库,可以通过以下方式对其进行修复:
The second error that you get with Eclipse is a successive step: your classpath contains the jar library but it is not able to find the native library attached to it, you can fix it in the following way:
这篇关于Java-库路径错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!