I am trying to get the directory path of the properties file which is located inside the resource directory using the below code.
public String getFilePath(String fileName){
File file = new File(getClass().getClassLoader().getResource(fileName).getFile());
return file.getParent()+"/";
}
My setup will have 3 modules. Module1 has 2 & 3 as a dependency in maven. each module has its properties file inside the root resource directory - src/main/resources/app.properties
Now if I try to load the path of config.properties from module 2 singleton class using above method, I get the path of module3 properties file. How to get the path of the 2nd module's properties file.
Thanks in advance.
UPDATE The answer given in the duplicate question is, to take all resource files and check for the specific string in the path exist or not. I would like to directly get the resource file from the root directory which must be closer to the given class reference.