I have a Spring Boot application using Google Pub Sub API. I need to inject Google credentials and other properties using file credentials.json
. I put the file in my src/main/resources
(otherwise, it will not put the file in the built jar) like this:
spring.cloud.gcp.credentials.location=file:src/main/resources/credentials.json
However, when I build the jar, this file is placed in the root directory and this path is no longer valid. So I am able to run my application from Eclipse, since by the that time, the file is still in my resources directory but I can't run it as a standalone jar after built because the path is suddently just file:credentials.json
.
Is there some easy way how to specify the path as relative so it works both in IDE and when running my jar? I can inject the path through env. variables but I would do so only if absolutely necessary.
If you use the classpath
prefix then Spring will look for the file on your classapth.
If you put the file in src/main/resources
then Maven will, by default, copy it to the root of your classpath and it will then be addressable as follows:
spring.cloud.gcp.credentials.location=classpath:credentials.json
This should hold true whether ...
src/main/resources
to the root of your classpath - typically target/classes
src/main/resources
to the root of your JARIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With