[英]Compiling a java program to a jar errors in eclipse
I have created a Java program. 我已经创建了一个Java程序。 It it is a game made with LWJGL.
它是用LWJGL制作的游戏。 I have decided to import some textures with the built in Texture class from LWJGL (LWJGL is Light Weight Java Graphics Library with opengl).
我决定使用LWJGL的内置Texture类导入一些纹理(LWJGL是带有opengl的轻量级Java图形库)。 In Eclipse I have put src/imagename.png.
在Eclipse中,我放置了src / imagename.png。 It works in Eclipse.
它可以在Eclipse中使用。 I export it into a jar file and run it (After putting required libraries and natives) and it does not run and can't find the file.
我将其导出到jar文件中并运行(放入所需的库和本机之后),它无法运行并且找不到该文件。 So, I tried removing that and putting imagename.png.
因此,我尝试将其删除并放入imagename.png。 That didn't work either.
那也不起作用。 I tried putting /imagename.png and it still didn't work.
我尝试将/imagename.png放进去,但仍然没有用。 What should I do?
我该怎么办?
try {
player = TextureLoader.getTexture("PNG", new FileInputStream(new File("src/player.png")));
} catch (IOException e) {
e.printStackTrace();
Thanks in advanced. 提前致谢。
Class.getResourceAsStream()或ClassLoader.getResourceAsStream()是从Classpath获取文件的正确方法,如果要从jar内加载文件,则应尝试这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.