Load a resource contained in a jar

It sounds like you’re then trying to load the resource using a FileInputStream or something like that. Don’t do that: instead of calling getResource, call getResourceAsStream and read the data from that.

(You could load the resources from the URL instead, but calling getResourceAsStream is a bit more convenient.)

EDIT: Having seen your updated answer, it seems other bits of code rely on the data being in a physical single file in the file system. The answer is therefore not to bundle it in a jar file in the first place. You could check whether it’s in a separate file, and if not extract it to a temporary file, but that’s pretty hacky IMO.

Leave a Comment