1

To get the application's path, I call the following Java command:

System.getProperty("user.dir")

This works just fine if the app is launched directly. On Windows and OS X, this also works if the app is launched via a shortcut and alias respectively.

However, when the app is launched via a Linux link (in Linux Mint, made by right-clicking on the file and choosing "Make Link", then moving it somewhere else), the command returns the path of the shortcut, rather than the path of the application itself. Is there a way that I can get the true path of the app, rather than the path of the link pointing to the app?

Thunderforge
  • 19,637
  • 18
  • 83
  • 130
  • Which path are you trying to get? `System.getProperty("user.dir")` returns the directory you started the JVM from (see [this comment](http://stackoverflow.com/questions/16239130/java-user-dir-property-what-exactly-it-means#comment23231285_16239152)) - which will indeed default to the directory of the destination file on Windows, but will be the directory of the symlink on Linux. -- To get the directory of the jar- or class-file, you will apparently have to jump through a few more hoops: http://stackoverflow.com/a/320595/1114687 – n.st Oct 03 '13 at 14:03
  • I'm trying to get the directory of the destination file. In other words, I want the equivalent String that I would get by calling `System.getProperty("user.dir")` on OS X and Windows, even when launched from a shortcut. I'm not sure if this is a bug in Java for Linux or if it's just different. – Thunderforge Oct 03 '13 at 14:08

1 Answers1

0

System.getProperty("user.dir") returns the directory you started the JVM from (see this comment). When you used a shortcut or symlink to start your program, this defaults to the directory of the destination file on Windows1, but will be the directory of the symlink on Linux.

To get the directory of the jar- or class-file, you will have to jump through a few more hoops: https://stackoverflow.com/a/320595/1114687

1: unless you change the "working directory" of the shortcut

Community
  • 1
  • 1
n.st
  • 946
  • 12
  • 27