简体   繁体   English

如何将资源保留在jar文件中而不需要外部文件夹?

[英]How to leave resources in the jar file to not need external folders?

I am finishing my first game in Java, called SpaceWar. 我正在用Java完成我的第一个游戏SpaceWar。 But to build the project requires that the resources folder (where I put my Sprites etc ...) is in the same place the jar file. 但是要构建项目,需要将资源文件夹(我将Sprites等放置在其中)放在jar文件的同一位置。 I wanted to know a way to let the images inside the jar file, because it is much better because it prevents the user from deleting accidentally. 我想知道一种将图像放入jar文件的方法,因为它更好,因为它可以防止用户意外删除。

Place your images into part of your java packages . 将图像放入Java包的一部分中。 For example, com.project.images 例如com.project.images

and then you may need use the following in your code : 然后您可能需要在代码中使用以下内容:

getClass().getResource("com/project/images/picture.bmp"));

to access the images. 访问图像。

then you images will be part of the jar. 那么您的图像将成为罐子的一部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM