从jar文件中获取相对路径

Get relative path from jar file

我试图到达 Ubuntu 中相对于当前 jar 文件的特殊路径。 在 Windows 它工作没有任何问题:

String jarPath = Configuration.class.getProtectionDomain().getCodeSource().getLocation().getPath();
File f = new File(jarPath+"/../../configurationFile.xml");

但是,在 Linux 中,我总是得到 jar 文件,但我无法后退两个目录到 configurationFile.xml

/some/directory/where/xml/is/located/xyz.jar/configurationFile.xml: Not a directory

但是,如果我这样做

pwd /some/directory/where/xml/is/located/xyz.jar/../../

它没有任何问题。

我这里做错了什么?

我想不通。

仅使用路径中的目录。 确定 jar 文件的路径后,将路径提取到其目录并仅使用目录。