• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Fat jar unable to find classpath file inside /resources package

 
Ranch Hand
Posts: 658
2
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I created a fat jar using Spring boot. Inside the bootstrap.yml I am trying to access a file which is under /resources only.
location: classpath:secret.json

But I am getting java.io.FileNotFoundException: class path resource [secret.json] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/Users/test/Downloads/Demo/demo-api/target/demo-api-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/secret.json

The same is working in IDE. What could be the wrong?

Here is the decompiled jar file structure screenshot and package structure

Screenshot-2021-03-17-at-8.22.31-PM.png
[Thumbnail for Screenshot-2021-03-17-at-8.22.31-PM.png]
Screenshot-2021-03-17-at-11.02.04-PM.png
[Thumbnail for Screenshot-2021-03-17-at-11.02.04-PM.png]
 
Bartender
Posts: 2266
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you use ResourceLoader to load the json file?
Reference:
https://smarterco.de/java-load-file-from-classpath-in-spring-boot/
 
Puspender Tanwar
Ranch Hand
Posts: 658
2
Java
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic