Skip to content

open resource with relative path in Java

In my Java app I need to get some files and directories.

This is the program structure:

./package1/resources/repository/modules/   -> this is the dir I need to get
./package1/resources/repository/SSL-Key/cert.jks    -> this is the file I need to get

guiclass loads the resourcesloader class which will load my resources (directory and file).

As to the file, I tried


in order to get the real path, but this way does not work.

I have no idea which path to use for the directory.


Supply the path relative to the classloader, not the class you’re getting the loader from. For instance: