1

I have a java application which uses the following line

new File(new File(".").getAbsolutePath())

When running the program from a terminal as:

~/Documents/Routes$ java -jar myApp.jar

The program correctly interprets the java line as folling

/home/user/Documents/Routes

This route is the working directory of the terminal. However if I double click the myApp.jar the result is a bit random

/home/user/Download/.

Which could be the cause that I am getting an incorrect "running" path ?

Ricard Molins
  • 408
  • 1
  • 6
  • 20
  • 1
    Is this a Linux system? Looks like it. – Benjamin Urquhart Apr 17 '19 at 19:07
  • 3
    Possible duplicate question? https://stackoverflow.com/questions/320542/how-to-get-the-path-of-a-running-jar-file –  Apr 17 '19 at 19:11
  • 2
    Possible duplicate of [How to get the path of a running JAR file?](https://stackoverflow.com/questions/320542/how-to-get-the-path-of-a-running-jar-file) – KevinO Apr 17 '19 at 19:16
  • @Benson99 He knows how to get the path. He wants to know why it's different depending on how he launches the application. – Bakon Jarser Apr 17 '19 at 19:48
  • The content of that post (I thought, anyhow) was that some operating systems will resolve to the command line root rather than the actual jar file. –  Apr 17 '19 at 19:52
  • @KevinO I will look at the answer of your comment. It looks interesting because it differentiates between the running directory and the jar file location. Will provide feedback once tested – Ricard Molins Apr 21 '19 at 16:07

0 Answers0