I have created a simple JAVA project, which accesses an internal file called config.json and writes content to a file output.txt. As I did not want to send arguments to the main class, I added my config.json to the resource folder.
I am able to run the application in Eclipse without any issue.
Both this.getClass().getClassLoader().getResource("resource/config.json")
and this.getClass().getResource("/resource/config.json")
are able to locate the file from the path C:/Users/divya_raibagkar/workspace/TestProject/**bin**/resource/config.json
But when I export it to JAR and try to execute from command prompt using java -jar D:/Test.jar
, I get the following error:
Returned file path: resource/config.json
Loading JSON config file:
java.io.FileNotFoundException: resource\config.json (The system cannot find the path specified)
Any lead to resolve this issue is highly appreciated. Thank you.