简体   繁体   中英

how to get all images list from resources sub folder in run time , after making run able jar file

Step 1 : when I run my project in myeclipse at development mode then it runs perfectly.
Step 2 : So I make runable jar file
Step 3 : I make run.bat file to run my project which is desktop application.

On Step 3, file not found etc error is coming but when I run my desktop application in myeclipse then no error comes like file not found. It means after making runable jar file, my code is not able to find my images resources folder, this images resource is available on development mode.

This could be because when you run in eclipse you run from files, so you can read images as regular files. When you run from jar, you don't have files anymore, you have only that jar. It has that images inside, but you need to read them using

InputStream is = YourClassName.class.getResourceAsStream(packageAndFileName);

then you could use ImageIO class to read the stream into image

the root of the project is denominated by "/" , so the path should be like

"/packagePart1/packagePart2/fileName.ext"

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