0

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

        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();
    }```
Komal Kadam
  • 668
  • 1
  • 5
  • 17
  • Please [edit] the question and post file reading part code here. It will be useful to resolve your issue. – Shashanth Jun 11 '21 at 16:51

0 Answers0