• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Fat jar unable to find classpath file inside /resources package

 
Ranch Hand
Posts: 654
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: 2061
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: 654
2
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the issue with spring cloud config library.

https://stackoverflow.com/questions/50981257/spring-boot-project-jar-file-not-reading-file-placed-on-classpath/50990669#50990669
https://github.com/spring-cloud/spring-cloud-gcp/issues/339
 
Note to self: don't get into a fist fight with a cactus. Command this tiny ad to do it:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic