当我运行 .jar 时,出现“java.library.path 中没有 lwjgl”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6588799/
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
When I run the .jar, I get a "No lwjgl in java.library.path" error
提问by Stephen Wilkins
I'm making a basic game in Java using the LWJGL Library via Netbeans.
我正在通过 Netbeans 使用 LWJGL 库在 Java 中制作一个基本游戏。
I've created a library with the lwjgl, lwjgl_util, and jinput .jar's, and I added -Djava.library.path=C:\LWJGL\native\windows to the "Run" category in the project's properties.
我已经用 lwjgl、lwjgl_util 和 jinput .jar 创建了一个库,并将 -Djava.library.path=C:\LWJGL\native\windows 添加到项目属性中的“运行”类别中。
When I run the file in Netbeans, it runs perfectly with no issue. But when I run the .jar via double-clicking the file, nothing pops up (not even the momentary cmd error window, as far as I can tell). And when I run the file via command line, I get:
当我在 Netbeans 中运行该文件时,它运行完美,没有任何问题。但是当我通过双击文件运行 .jar 时,什么也没有弹出(据我所知,即使是暂时的 cmd 错误窗口也没有)。当我通过命令行运行文件时,我得到:
C:\Users0160765>java -jar "C:\Users0160765\Documents\NetBeansProjects\Game
\dist\Game.jar"
Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.libr
ary.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.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 game.Draw.createWindow(Draw.java:198)
at game.Draw.init(Draw.java:214)
at game.Draw.run(Draw.java:56)
at game.Main.main(Main.java:9)
I've tried moving the DLL's and .jar library files around to the 'lib' folder in the same directory as Game.jar, and moving them to the same directory as Game.jar, but I get the same error. Could someone help me as to why I can't seem to get this working outside of netbeans?
我已经尝试将 DLL 和 .jar 库文件移动到与 Game.jar 相同目录中的“lib”文件夹,并将它们移动到与 Game.jar 相同的目录,但我得到了相同的错误。有人可以帮助我解释为什么我似乎无法在 netbeans 之外进行这项工作吗?
采纳答案by Gavin
you have to point the jvm to where the native files are located using a command line parameter -Djava.library.path="path/to/natives". You could use a batch (.bat) file to specify this and start your application for you.
您必须使用命令行参数 -Djava.library.path="path/to/natives" 将 jvm 指向本机文件所在的位置。您可以使用批处理 (.bat) 文件来指定它并为您启动应用程序。
Alternatively you can use a tool like JarSpliceto create a single executable jar file from all your jars and at the same time include your native files inside it. It automates the tricky part of specifying the natives manually and provides a nicer end user experience.
或者,您可以使用JarSplice 之类的工具从所有 jar 文件创建一个可执行的 jar 文件,同时在其中包含您的本机文件。它自动化了手动指定本机的棘手部分,并提供了更好的最终用户体验。
To use JarSplice just select your game.jar, lwjgl.jar, lwjgl_util.jar, and jinput.jar in the jars tab. Then all the *.dll, *.so, *.dylib and *.jnilib files in the natives tab. Add your main class on the class tab and create the single executable jar.
要使用 JarSplice,只需在 jars 选项卡中选择您的 game.jar、lwjgl.jar、lwjgl_util.jar 和 jinput.jar。然后是 natives 选项卡中的所有 *.dll、*.so、*.dylib 和 *.jnilib 文件。在类选项卡上添加您的主类并创建单个可执行 jar。
回答by Ben Hymanson
LWJGL needs the native components for your particular platform to be in java.library.path
. These are in the subdirectory native
in the LWJGL distribution and end in .so
on Linux, OSX and Solaris and .dll
for windows.
LWJGL 需要您特定平台的本机组件以java.library.path
. 它们位于native
LWJGL 发行版的子目录中,并以.so
Linux、OSX 和 Solaris 以及.dll
Windows 为结尾。
回答by Jim
And yet another way to do this is with Java Web Start (jnlp): http://lwjgl.org/forum/index.php?topic=3763.0
另一种方法是使用 Java Web Start (jnlp):http://lwjgl.org/forum/index.php?topic= 3763.0
This makes sharing your project easier in some ways.
这使得在某些方面更容易共享您的项目。
回答by WockaWocka
I had this problem and fixed it using jarSplice (http://ninjacave.com/jarsplice)
我遇到了这个问题并使用 jarSplice (http://ninjacave.com/jarsplice) 修复了它
make sure you delete all of the preplaced natives in your jar before you create the fat jar, otherwise it will create a duplicate error
在创建胖 jar 之前,请确保删除 jar 中所有预先放置的本地人,否则会创建重复错误
回答by Alan Sorrill
When I had this issue, it was because i accidentally put the argument to specify the location of the natives (-Djava.library.path=/native/) in the field called 'Arguments' under the run category of the options panel, instead of 'vm Options'. As seen here: http://s30.postimg.org/6f90akidt/Capture.png
当我遇到这个问题时,是因为我不小心在选项面板的运行类别下的名为“Arguments”的字段中放置了指定本地人位置的参数(-Djava.library.path=/native/),而不是'vm 选项'。如下所示:http: //s30.postimg.org/6f90akidt/Capture.png
回答by efeyc
I also got the same error and then realised that I named the file "my_lib.zip" instead of "my_lib.jar". Maybe it may help someone.
我也遇到了同样的错误,然后意识到我将文件命名为“my_lib.zip”而不是“my_lib.jar”。也许它可以帮助某人。
回答by Stephen C
Another thing to check:
另一件事要检查:
- If you are using a 32 bit JVM, you need 32 bit libraries. (Even on a 64 bit OS)
- If you are using a 64 bit JVM, you need 64 bit libraries.
- 如果您使用的是 32 位 JVM,则需要 32 位库。(即使在 64 位操作系统上)
- 如果您使用的是 64 位 JVM,则需要 64 位库。