I have a jar file with bundled resources (language model binary files) that need loading at run time. The directory structure within the jar is
tagger/app.class
tag
You can't access a resource in a Jar file via java.io.File
. You should provide an alternate constructor for SentenceDetector
which either accepts an InputStream
rather than a String
, or which accepts an URL
and uses URL.openStream()
to get an InputStream
.
It sounds like that should be fine, if the binary is definitely in the right place and the jar file is definitely in the class path. (I assume it can find the class itself? I'd expect so, given that you're using this.getClass()
).
One thing which might be causing issues is filename casing - when it's loading the file from the file system, if you're using Windows that'll be case insensitive; in a jar file it'll be case sensitive. Check the case in code matches the case in the jar file.