Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access classpath files in a spring-boot jar?

I didn't manage to access any classpath files in my spring-boot jar.

I tried the following :

Resource resource = new ClassPathResource("myResourceFile");

But when I tried to read it, I got the following message

it does not reside in the file system: jar:file:/myjar.jar!/BOOT-INF/classes!/myResourceFile

I noticed the 2 exclamation marks. The first is to indicate the resource is inside a jar, but I don't know if the second one (after classes) is involved in my problem.

Thanks for your help.

I use spring-boot 1.4.5 and spring-* 4.3.7.

like image 251
matth3o Avatar asked Sep 20 '25 17:09

matth3o


1 Answers

If you need to load an image from classpath , you can use something like below:

new ClassPathResource("/static/img/logo.png");

Resource Path:

main -> resources -> static.img -> logo.png
like image 102
Tiny Avatar answered Sep 23 '25 07:09

Tiny