I am trying to move my spring application to spring boot
In my earlier spring application, I had two modules core and war. In core, the module was added as a dependency in war. In the core module, I read folders(iterate over the nested folders and load files) specified in resources. This used to work when I used to run it as tomcat.
Now I have migrated my application to spring boot. Reading of folder works in IDE but when I try to run it as
java -jar dnow/war/target/war.jar
it gives me an error
java.io.FileNotFoundException: class path resource [datasources] cannot be resolved to absolute file path because it does not reside in the file system:
jar:file:/Users/kkadam/Work/repos/Project/dnow/war/target/war.jar!/BOOT-INF/classes!/datasources
My Code is given below
public static File[] getListOfFiles(String folder) {
File file;
File[] listFiles = null;
String property = Utils.getConfDirectoryPath();
if (!Utils.isEmpty(property)) {
try {
if (!property.endsWith("/"))
property = property + "/";
file = new File(property + folder);
listFiles = file.listFiles();
} catch (Exception e) {
logger.info("Folder " + folder + "does not found. Reading from resources");
}
}
if (listFiles != null)
return listFiles;
else {
return listFilesFromClassPath(folder);
}
}
public static File[] listFilesFromClassPath(String folder) {
File file;
URL url = FileUtils.class.getClassLoader().getResource(folder);
file = new File(url.getPath());
return file.listFiles();
}