I have a.jar file. I want to its path where ever it is when it running.
I use this code :
System.getProperty("user.dir")
it works in windows but not work in unix
I have a.jar file. I want to its path where ever it is when it running.
I use this code :
System.getProperty("user.dir")
it works in windows but not work in unix
If you really really need this, here's a solution:
MyClass.class.getProtectionDomain().getCodeSource().getLocation().getPath();
It is, however, far from pretty ;). Consider using other mechanisms. (Source: a slideset of mine)
the answer is :
in windows :
String yourJarName="yourJarName.jar";
String Jar_path= MyClass.class.getProtectionDomain().getCodeSource().getLocation().getPath().replace(yourJarName,"").substring(1);
in unix :
String yourJarName="yourJarName.jar";
String Jar_path= MyClass.class.getProtectionDomain().getCodeSource().getLocation().getPath().replace(yourJarName,"");