简体   繁体   中英

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

I am finishing my first game in Java, called 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. 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.

Place your images into part of your java packages . For example, 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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