For a project, I created an executable jar using the maven shade plugin. So far it runs, as it should, double clicking it starts the application just like executing the main method in my IDE. My next task is to have a properties file (named connection.properties), which is needed for the application, outside of the jar (at best in the same directory that the jar is in). I have already successfully excluded it from the jar with a filter, but I don't know how make the jar use the file while it is in the same directory, but not in the jar itself. Any help or comments would be appreciated very much.
Asked
Active
Viewed 125 times
-1
-
1Find the path of the executed jar, then resolve the properties' file name and read/write it... – deHaar Oct 22 '19 at 12:02
2 Answers
0
if the jar is in the current directory:
Paths.get("").resolve('myfile')
if the jar is elsewhere, see That answer

eyalka
- 21
- 5
0
You can do the following to find the file in the current path (where the jar is running from)
File propertyFile = new File(Paths.get("").toAbsolutePath().toString() + File.separatorChar + "connection.properties");

Ioannis Barakos
- 1,319
- 1
- 11
- 16