1
我有一个.jar文件。我想要它的运行路线。如何在unix上找到我的运行jar文件路径?
我用这个代码: System.getProperty("user.dir")
它工作在Windows,但在UNIX中不起作用
我有一个.jar文件。我想要它的运行路线。如何在unix上找到我的运行jar文件路径?
我用这个代码: System.getProperty("user.dir")
它工作在Windows,但在UNIX中不起作用
如果你真的很需要这个,这里有一个解决方案:从漂亮
MyClass.class.getProtectionDomain().getCodeSource().getLocation().getPath();
它,然而,远)。考虑使用其他机制。 (来源:a slideset of mine)
的答案是:
在窗口:
String yourJarName="yourJarName.jar";
String Jar_path= MyClass.class.getProtectionDomain().getCodeSource().getLocation().getPath().replace(yourJarName,"").substring(1);
在UNIX
:
String yourJarName="yourJarName.jar";
String Jar_path= MyClass.class.getProtectionDomain().getCodeSource().getLocation().getPath().replace(yourJarName,"");
'定位yourfile.jar'或'DIR C:\ yourfile。 jar/s/a/p'? –
准确重复:http://stackoverflow.com/questions/320542/how-to-get-the-path-of-a-running-jar-file 报告关闭。 –
没有重复,我看到它,但它不是我想要的。 我使用这段代码:System.getProperty(“user.dir”)它在窗口中工作,但不能在unix中工作 –