线程“main”中的异常 java.lang.UnsatisfiedLinkError:java.library.path 中没有 lwjgl
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13416652/
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
Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
提问by corazza
I'm building the basic Slick game example explained here: http://slick.cokeandcode.com/wiki/doku.php?id=01_-_a_basic_slick_game, and I'm running into some problems. Specifically, the game compiles just fine, but when I try to run it, Java complains:
我正在构建这里解释的基本 Slick 游戏示例:http://slick.cokeandcode.com/wiki/doku.php?id=01_-_ a_basic_slick_game,我遇到了一些问题。具体来说,游戏编译得很好,但是当我尝试运行它时,Java 抱怨:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1856)
at java.lang.Runtime.loadLibrary0(Runtime.java:845)
at java.lang.System.loadLibrary(System.java:1084)
at org.lwjgl.Sys.run(Sys.java:75)
at java.security.AccessController.doPrivileged(Native Method)
at org.lwjgl.Sys.doLoadLibrary(Sys.java:68)
at org.lwjgl.Sys.loadLibrary(Sys.java:84)
at org.lwjgl.Sys.<clinit>(Sys.java:101)
at org.lwjgl.opengl.Display.<clinit>(Display.java:128)
at org.newdawn.slick.AppGameContainer.run(AppGameContainer.java:39)
at java.security.AccessController.doPrivileged(Native Method)
at org.newdawn.slick.AppGameContainer.<clinit>(AppGameContainer.java:36)
at SlickBasicGame.main(SlickBasicGame.java:79)
This is my source code:
这是我的源代码:
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
public class SlickBasicGame extends BasicGame{
Image plane = null;
Image land = null;
float x = 400;
float y = 300;
float scale = 1;
public SlickBasicGame()
{
super("Slick2D Path2Glory - SlickBasicGame");
}
@Override
public void init(GameContainer gc)
throws SlickException {
plane = new Image("data/plane.png");
land = new Image("data/land.jpg");
}
@Override
public void update(GameContainer gc, int delta)
throws SlickException
{
Input input = gc.getInput();
if(input.isKeyDown(Input.KEY_A))
{
plane.rotate(-0.2f * delta);
}
if(input.isKeyDown(Input.KEY_D))
{
plane.rotate(0.2f * delta);
}
if(input.isKeyDown(Input.KEY_W))
{
float hip = 0.4f * delta;
float rotation = plane.getRotation();
x+= hip * Math.sin(Math.toRadians(rotation));
y-= hip * Math.cos(Math.toRadians(rotation));
}
if(input.isKeyDown(Input.KEY_2))
{
scale += (scale >= 5.0f) ? 0 : 0.1f;
plane.setCenterOfRotation(plane.getWidth()/2.0f*scale, plane.getHeight()/2.0f*scale);
}
if(input.isKeyDown(Input.KEY_1))
{
scale -= (scale <= 1.0f) ? 0 : 0.1f;
plane.setCenterOfRotation(plane.getWidth()/2.0f*scale, plane.getHeight()/2.0f*scale);
}
}
public void render(GameContainer gc, Graphics g)
throws SlickException
{
land.draw(0, 0);
plane.draw(x, y, scale);
}
public static void main(String[] args)
throws SlickException
{
AppGameContainer app =
new AppGameContainer( new SlickBasicGame() );
app.setDisplayMode(800, 600, false);
app.start();
}
}
The only change I've made to the original (which reports the same error), was that I have removed the package declaration.
我对原始文件所做的唯一更改(报告了相同的错误)是我删除了包声明。
I downloaded Slick from here: http://slick.cokeandcode.com/, by clicking on the "Download Full Distribution" link, and here's how my Slick folder looks like:
我从这里下载了 Slick:http: //slick.cokeandcode.com/,点击“下载完整分发版”链接,这是我的 Slick 文件夹的样子:
I'm compiling the game with this command:
我正在使用以下命令编译游戏:
javac -cp lib/*:. SlickBasicGame.java
javac -cp lib/*:. SlickBasicGame.java
And trying to run it with this one:
并尝试用这个运行它:
java -cp lib/*:. SlickBasicGame
java -cp lib/*:. SlickBasicGame
回答by Saddam Abu Ghaida
Add a -Djava.library.path=path/to/dir
to the commandline or as an VM option in your IDE so that lwjgl is able to find the folder containing the native files.
将 a 添加-Djava.library.path=path/to/dir
到命令行或作为 IDE 中的 VM 选项,以便 lwjgl 能够找到包含本机文件的文件夹。