I have a program in which the properties file is in the same path as the program I'd like to run.
The properties file name is initialized at the start of the program with:
public static final String DEFAULT_PROPERTIES_FILE = "defaultProperties.properties";
The program runs perfectly when running it in the directory it itself is located in with:
java -jar program.jar
When running the program from another directory with:
java -jar path/program.jar
The program will not find the properties file and returns a:
java.io.FileNotFoundException: defaultProperties.properties (No such file or directory)
FIXED
I came up with a solution. It is possible to call the path of the class and give the path to the configurations file.
StringBuilder stringBuilder = new StringBuilder( PolicyBoosterTool.class.getProtectionDomain().getCodeSource().getLocation().getPath() );
String pathToFolderOfJarFile = stringBuilder.substring( 0, stringBuilder.lastIndexOf( "/" ) + 1);
DEFAULT_PROPERTIES_FILE = pathToFolderOfJarFile + "defaultProperties.properties";
Sadly I can't mark the case as solved for myself. Any improvements to this are always welcome. Thank you for your help everyone!