I want make a directory and all its files available to a method. The directory and files are located in
src/main/resources/images
and inside the library jar at runtime. I am reading the directory with
File directory = new File(getClass().getResource("/images").getFile());
Inspecting the contents of directory
with
log.info("directory=" + directory.toString());
log.info("directory.isDirectory()=" + directory.isDirectory());
log.info("directory.isFile()=" + directory.isFile());
log.info("directory.canRead()=" + directory.canRead());
gives
- directory=file:/home/leevilux/.m2/repository/groupid/library/1.0-SNAPSHOT/library-1.0-SNAPSHOT.jar!/images
- directory.isDirectory()=false
- directory.isFile()=false
- directory.canRead()=false
So clearly it is not a directory, not a file and I can not read. But getFile
did find something, because if I use getResource("/blabla")
instead (which doesn't exist) then a null pointer expection is thrown (java.lang.NullPointerException
).
Do I have to extract the jar to create "normal" paths? And if so, how?