I'm Facing a FileNotFoundException while loading a JSON file which is in class path of Java jar using docker containers, it is a Spring-Boot application. This JSON file is available in resource folder . I'm Able to see the JSON file in docker under ./target/classes/ path.
Resource resource = resourceLoader.getResource("classpath:folderNm/file.json");
HashMap<String, String> headerMapping = (HashMap<String, String>) parser.parse(new FileReader(resource.getFile().getAbsolutePath()));
But I get this exception:
java.io.FileNotFoundException: class path resource [folderNm/file.json] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/app.jar!/folderNm/file.json
I tried
-> resource.getFile().getPath();
-> resource.getFile().getCanonicalPath();
-> "./target/classes/folderName/fileName
" (hardcoded FilePath location)
-> "/app.jar!/folderNm/file.json
" (hardcoded FilePath location)
InputStream inputStream = getClass().getResourceAsStream("xyz.json");
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
StringBuilder responseStrBuilder = new StringBuilder();
String inputStr;
while ((inputStr = br.readLine()) != null)
responseStrBuilder.append(inputStr);
none of the way above are running. Kindly Suggest a way to resolve this issue.