4

I have a situation where an app I'm writing works fine from the IDE but fails when deployed into a jar. What I see is NULL pointer exception. What I'm trying to do is get a URL resource of a directory and then iterate through the files in that directory. The URL seems to work but I can't find a way to get the files from it.

So I can't seem to get a file list (because this is really a resouce list inside the jar).

Any ideas?

TIA

        URL scriptFolder = getClass().getResource("/scripts/");
        log.debug(scriptFolder);

        if (scriptFolder != null) {
            File folder = new File(scriptFolder.getFile());
            File[] files = folder.listFiles();
            // files is NULL here.
            for (int i = 0; i < files.length; i++) {
                if (files[i].isFile()) {
                    log.debug("File " + files[i].getName());
                }
            }
        }
sproketboy
  • 8,967
  • 18
  • 65
  • 95

1 Answers1

3

See "List files inside a JAR".

Community
  • 1
  • 1
erickson
  • 265,237
  • 58
  • 395
  • 493