I am working on a Spring Boot application runned as executable jar. In my code I am trying to retrieve the folder where is located the runned jar file. But I am finding some difficulties. I have done in this way:
File jarFile = new File(BeanConfig.class.getProtectionDomain().getCodeSource().getLocation().getPath());
String jarFolder = jarFile.getParentFile().getPath();
System.out.println("FOLDER: " + jarFolder);
The problem is that, doing in this way, the printed output is something like this:
FOLDER: file:/home/andrea/git/notartel-api-batch/target/UpdateInfoBatch-0.0.1-SNAPSHOT.jar!/BOOT-INF
And this is not what I need because I need the path of the directory containing my jar file that int this case is this one: /home/andrea/git/notartel-api-batch/target/
What is wrong? What am I missing? How can I try to fix this behavior in order to retrieve the path of the directory containing my jar file?