1

My Spring boot application is using an external jar which is loading a file abc.properties. But when I run my application using java -jar its not able to find file. its trying to find the file in the file:/.jar!/BOOT-INF/classes!/abc.properties

I have kept the abc.properties file in the same level where I have kept the jar.

Can anyone please suggest me how to fix this issue.

2
  • Its code is probably incorrect. But you haven't posted its code... Commented Dec 10, 2018 at 7:37
  • Please post example of the code which consumes the property file. Commented Dec 10, 2018 at 7:47

2 Answers 2

1

To add different files you can use the spring.config.location properties which takes a comma-separated list of property files or file location (directories).

Sign up to request clarification or add additional context in comments.

5 Comments

How would that help for EXTERNAL .jar?
I tried this java -jar selfcare-18.12.0.jar --spring.config.name=config.db.properties --spring.config.location=classph:/home/tdatta/workspace/tempselfcare/ but still got the error java.io.FileNotFoundException: file:/home/tdatta/workspace/tempselfcare/selfcare/selfcare-18.12.0.jar!/BOOT-INF/classes!/config.db.properties (No such file or directory)
Is this working? java -jar selfcare-18.12.0.jar --spring.config.location=/home/tdatta/workspace/tempselfcare/config.db.properties
nope its not working, getting error: java.io.FileNotFoundException: file:/home/tdatta/workspace/tempselfcare/selfcare/selfcare-18.12.0.jar!/BOOT-INF/classes!/config.db.properties (No such file or directory)
Thread.currentThread().getContextClassLoader().getResource(fileName)
0

You can do like this:

set the following valuea in your OS

set SPRING_CONFIG_NAME=<name of your confif file> 
set SPRING_CONFIG_LOCATION=classpath:<location of your config file>

Then run your jar

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.