Can't start .jar file (using LWJGL)

こ雲淡風輕ζ 提交于 2019-12-29 08:52:16

问题


Good day!

I created jar file (using Netbeans) and i can't start it. This project uses lwjgl libraries. Inside my IDE it works well.

I use next command:

java -jar LWJGL_TimerExample.jar 

Answer is:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1758)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1045)
at org.lwjgl.Sys$1.run(Sys.java:73)
at java.security.AccessController.doPrivileged(Native Method)
at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
at org.lwjgl.Sys.loadLibrary(Sys.java:82)
at org.lwjgl.Sys.<clinit>(Sys.java:99)
at org.lwjgl.opengl.Display.<clinit>(Display.java:130)
at Sourse.TimerExample.start(TimerExample.java:32)
at lwjgl_timerexample.Main.main(Main.java:21)

Other projects (without this libraries) work fine. How can i solve this error?

My Manifest is:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.1
Created-By: 1.6.0_26-b03-384-10M3425 (Apple Inc.)
Main-Class: lwjgl_timerexample.Main
Class-Path: lib/jinput.jar lib/lwjgl.jar lib/lwjgl_util.jar
X-COMMENT: Main-Class will be added automatically by build

回答1:


It's not going to work the way you're trying to currently do it, since you need to have the native files along side the jar and point to them via the '-Djava.library.path' parameter.

If you just want a single jar and want to avoid the hassle of the command line and native files use the JarSplice tool. JarSplice is easy to use and will automatically handle the native file stuff for you.

1) Simply export your project (class and resources) to a jar (easier just to do it through your IDE).

2) Then run JarSplice, add all the jars you need to the jars tab (your app jar, lwjgl.jar, and any other external jar you're using).

3)Then on the natives tab add all the natives files (windows *.dll, linux *.so, mac *.dylib & *.jnilib).

4)On the class tab add your main class. Then create your jar.

You can then run this jar just by double clicking it (or if you wish via command line using 'java -jar yourapp.jar').




回答2:


From the LWJGL wiki:

LWJGL consists of two parts, a java part and a native code part. You must setup both of these parts properly in order for lwjgl to work. In order to setup the java part you must add lwjgl.jar to the classpath (as an external library jar). As for the native part (*.dll files on windows, *.so on linux, *.jnilib on mac, etc) you must tell java which folder the natives are located in for LWJGL to be able to find them (use the -Djava.library.path=path/to/dir vm parameter to do this).

It seems that you're missing the second part - having the native library on your java.library.path.



来源:https://stackoverflow.com/questions/6749141/cant-start-jar-file-using-lwjgl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!