当我运行.jar时,在java.library中会得到一个“No lwjgl”。路线”错误

时间:2022-09-03 22:30:55

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。路径=C:\LWJGL本地\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:\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)

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库文件移动到与游戏相同的目录中的“lib”文件夹。将它们移动到与游戏相同的目录。jar,但是我得到了相同的错误。有人能帮我解释一下为什么在netbeans之外我还不能让它正常工作吗?

6 个解决方案

#1


9  

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/native”将jvm指向本地文件所在的位置。您可以使用一个批处理(.bat)文件来指定这一点,并为您启动应用程序。

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这样的工具从所有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,只需选择您的游戏。lwjgl jar。lwjgl_util jar。jar和jinput。jar在jars选项卡中。然后所有的*。dll,*。所以,*。dylib和*。jnilib文件在本机选项卡中。在class选项卡上添加主类并创建单个可执行jar。

#2


3  

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中。它们在LWJGL发行版的本地子目录中,以so结尾,在Linux、OSX和Solaris以及windows的.dll中。

#3


2  

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

当我遇到这个问题时,这是因为我不小心在options面板的run类别下输入了参数来指定本机(-Djava.library.path=/native/)的位置,而不是“vm选项”。如图所示:http://s30.postimg.org/6f90akidt/Capture.png

#4


0  

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: http://lwjgl.org/forum/index.php?

This makes sharing your project easier in some ways.

这使得分享你的项目在某些方面更容易。

#5


0  

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

在创建fat jar之前,请确保在jar中删除了所有预先放置的本机,否则它将创建一个重复错误。

#6


0  

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”。也许它能帮助某人。

#1


9  

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/native”将jvm指向本地文件所在的位置。您可以使用一个批处理(.bat)文件来指定这一点,并为您启动应用程序。

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这样的工具从所有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,只需选择您的游戏。lwjgl jar。lwjgl_util jar。jar和jinput。jar在jars选项卡中。然后所有的*。dll,*。所以,*。dylib和*。jnilib文件在本机选项卡中。在class选项卡上添加主类并创建单个可执行jar。

#2


3  

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中。它们在LWJGL发行版的本地子目录中,以so结尾,在Linux、OSX和Solaris以及windows的.dll中。

#3


2  

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

当我遇到这个问题时,这是因为我不小心在options面板的run类别下输入了参数来指定本机(-Djava.library.path=/native/)的位置,而不是“vm选项”。如图所示:http://s30.postimg.org/6f90akidt/Capture.png

#4


0  

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: http://lwjgl.org/forum/index.php?

This makes sharing your project easier in some ways.

这使得分享你的项目在某些方面更容易。

#5


0  

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

在创建fat jar之前,请确保在jar中删除了所有预先放置的本机,否则它将创建一个重复错误。

#6


0  

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”。也许它能帮助某人。