本文介绍了当我运行.jar时,我得到一个“java.library.path中的No lwjgl”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Java中使用LWJGL库通过Netbeans制作基本游戏。

I'm making a basic game in Java using the LWJGL Library via Netbeans.

我创建了一个库,包含lwjgl,lwjgl_util和jinput .jar ,并且我在项目属性中的运行类别中添加了-Djava.library.path = C:\LWJGL\\\
ative\windows。

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.

在Netbeans中运行该文件,它运行完美没有问题。但是,当我通过双击文件运行.jar时,没有弹出(即使是即时的cmd错误窗口,据我所知)。当我通过命令行运行该文件时,我得到:

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:

C:\Users\200160765>java -jar "C:\Users\200160765\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$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 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)

我试着将DLL和.jar库文件移动到Game目录下的lib文件夹。 jar,并将它们移动到与Game.jar相同的目录,但我得到相同的错误。

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?

推荐答案

你必须指向jvm到本地文件所在的位置,使用命令行参数-Djava.library.path =path / to / natives。您可以使用批处理(.bat)文件来指定并为您启动应用程序。

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.

也可以使用从所有jar创建一个单一的可执行jar文件,同时包括其中的原生文件。

Alternatively you can use a tool like JarSplice to 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,只需选择您的game.jar,lwjgl.jar,lwjgl_util.jar ,和jars选项卡中的jinput.jar。然后在本地选项卡中的所有* .dll,* .so,* .dylib和* .jnilib文件。在类选项卡上添加您的主类,并创建单个可执行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.

这篇关于当我运行.jar时,我得到一个“java.library.path中的No lwjgl”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 17:54