0

I'm trying to make an executable JAR so that anyone can download and run my application.

I'm trying to grab the path of a directory full of images so that I can traverse all images in the folder to perform some action on each one. It works fine when run from the IDE (Netbeans), but when run from the JAR file it doesn't work.

The folder that contains the images is located in the src folder -> graphics -> Textures.

Here is my code:

Path terPath = Paths.get(getClass().getResource("/graphics/Textures").toURI());
List<File> filesInFolder = Files.walk(terPath)
                            .filter(Files::isRegularFile)
                            .map(Path::toFile)
                            .collect(Collectors.toList());

The error happens in the first line when run from a JAR, but works perfectly fine when run from the IDE.

Thanks for your help.

  • What error message do you get? – folkol Aug 15 '16 at 00:17
  • When I print out the error message in a message dialog it just says null. – codes4food Aug 15 '16 at 00:29
  • Ok was able to get the exception: java.nio.file.FileSystemNotFoundException.. What is the usual way to distribute a JAR file and access directories and files that are contained within the JAR file? – codes4food Aug 15 '16 at 00:53
  • The "usual way" will depend on personal preference, the purpose of the jar and the build tool. Btw, to see error messages, start java on the command line with `java -jar myjar.jar`. Firstly, use `jar tf myjar.jar` to see if those images are in the jar as expected. If they are, copy/paste a couple of relevant lines of the output of `jar tf` into the question as example? If they aren't, you'll need to get them included into the jar. – Arjan Aug 15 '16 at 04:21
  • http://stackoverflow.com/questions/3369794/how-to-read-a-file-from-jar-in-java – folkol Aug 15 '16 at 13:13

0 Answers0