java错误路径错误,Java-库路径错误

I'm trying to start my java game but I have some troubles with the java command line:

Here is what I type:

C:\>java -Djava.library.path=%cd%\lib -jar game.jar

And here is what I got:

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

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.(Sys.java:98)

at org.lwjgl.opengl.Display.(Display.java:129)

at com.game.displaygui.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

lwjgl.jar has been put into the folder \lib.

Could you explain me with I got that?

Thanks.

解决方案

This because lwjgl library is made by two components:

the .jar file which contains Java code

and the native binary library (which can be .so or .dll or .dylib according to your OS)

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.

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:

iyPSW.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值