[英]Exported my Java game from eclipse, and it gets an error when running
I made a Java game in eclipse and when I run the executable .jar it starts up, and the loading screen starts, but then it stops and hangs. 我在eclipse中制作了一个Java游戏,当我运行可执行文件.jar时,它启动,加载屏幕启动,但随后停止并挂起。 I ran it using the command line: "Java -jar filename.jar" and when the loading screen stops it displays an error.
我使用命令行运行它:“Java -jar filename.jar”,当加载屏幕停止时,它显示错误。 This is what the cmd shows:
这就是cmd显示的内容:
D:\>java -jar Speedrunner.jar
60Ticks, FPS:1637
javax.imageio.IIOException: Can't read input file!
at javax.imageio.ImageIO.read(Unknown Source)
at com.daves.first_Scroller.utils.BufferedImageLoader.loadImage(Buffered
ImageLoader.java:26)
at com.daves.first_Scroller.utils.ResourceLoader.loadImages(ResourceLoad
er.java:17)
at com.daves.first_Scroller.Game.load(Game.java:100)
at com.daves.first_Scroller.Game.tick(Game.java:160)
at com.daves.first_Scroller.Game.run(Game.java:228)
at java.lang.Thread.run(Unknown Source)
60Ticks, FPS:1744
java.io.IOException: Can't read .\resources\Fonts\tight_pixel.ttf
at java.awt.Font.createFont(Unknown Source)
at com.daves.first_Scroller.utils.Fonts.registerFont(Fonts.java:36)
at com.daves.first_Scroller.utils.Fonts.<init>(Fonts.java:28)
at com.daves.first_Scroller.utils.ResourceLoader.loadFonts(ResourceLoader.java:30)
at com.daves.first_Scroller.Game.load(Game.java:105)
at com.daves.first_Scroller.Game.tick(Game.java:160)
at com.daves.first_Scroller.Game.run(Game.java:228)
at java.lang.Thread.run(Unknown Source)
60Ticks, FPS:1761
Mon Mar 17 12:18:08 GMT 2014 INFO:Initialising sounds..
Exception in thread "Thread-2" java.lang.UnsatisfiedLinkError: no lwjgl in java.
library.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:95)
at org.lwjgl.Sys.<clinit>(Sys.java:112)
at org.lwjgl.openal.AL.<clinit>(AL.java:59)
at org.newdawn.slick.openal.SoundStore$1.run(SoundStore.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at org.newdawn.slick.openal.SoundStore.init(SoundStore.java:292)
at org.newdawn.slick.Sound.<init>(Sound.java:83)
at com.daves.first_Scroller.utils.AudioPlayer.addSound(AudioPlayer.java:29)
at com.daves.first_Scroller.utils.ResourceLoader.loadSounds(ResourceLoader.java:35)
at com.daves.first_Scroller.Game.load(Game.java:110)
at com.daves.first_Scroller.Game.tick(Game.java:160)
at com.daves.first_Scroller.Game.run(Game.java:228)
at java.lang.Thread.run(Unknown Source)
EDIT - I looked in the .jar file and it contains all the Fonts and sprites it needs, and eclipse packaged all libraries needed into the .jar when I exported it. 编辑 - 我查看.jar文件,它包含它需要的所有字体和精灵,当我导出时,eclipse将所有需要的库打包到.jar中。
Seems like this file: 好像这个文件:
.\resources\Fonts\tight_pixel.ttf
is not included on your jar. 不包括在你的罐子里。 Probably it was available on your classpath when you executed your project from Eclipse, so you didn't notice it.
当您从Eclipse执行项目时,它可能在您的类路径中可用,因此您没有注意到它。
You need to tell java where to look for the LWJGL library. 你需要告诉java在哪里寻找LWJGL库。 Add the following to the command line:
将以下内容添加到命令行:
-Djava.library.path=path/to/dir
From the documentation: 从文档:
I keep getting an java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
我一直得到一个java.lang.UnsatisfiedLinkError:java.library.path中没有lwjgl
This is because the native part is not setup correctly.
这是因为未正确设置本机部分。 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.
将-Djava.library.path = path / to / dir添加到命令行或IDE中的VM选项,以便lwjgl能够找到包含本机文件的文件夹。
External link: http://www.lwjgl.org/wiki/index.php?title=Downloading_and_Setting_Up_LWJGL 外部链接: http ://www.lwjgl.org/wiki/index.php?title = Downloading_and_Setting_Up_LWJGL
It seems that .\\resources\\Fonts\\tight_pixel.ttf is not found. 似乎找不到。\\ resources \\ Fonts \\ tight_pixel.ttf。 That may be because before you were running you game from another path.
那可能是因为在你从另一条路上跑过你的游戏之前。 (Or you didn't include it in your package)
(或者你没有将它包含在你的包中)
The file .\\resources\\Fonts\\tight_pixel.ttf
is missing in your .jar
file. .jar
文件中缺少.\\resources\\Fonts\\tight_pixel.ttf
文件。
That's, what the line java.io.IOException: Can't read .\\resources\\Fonts\\tight_pixel.ttf
tells you. 那就是
java.io.IOException: Can't read .\\resources\\Fonts\\tight_pixel.ttf
行java.io.IOException: Can't read .\\resources\\Fonts\\tight_pixel.ttf
告诉你。
To solve it, integrate the folder resources
into the path. 要解决此问题,请将文件夹
resources
集成到路径中。 Then it's integrated into your exported .jar
file. 然后它被集成到导出的
.jar
文件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.