Is there any way by which we can find the current location from where the jar is forked, programmatically? Say I am executing a Jar from D:/Jars/myjar.jar
, so can I get that path from the code?
@AljoshaBre I tried this
try {
File file = new File(getClass().getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
System.out.println(file.getAbsolutePath());
} catch (Exception e1) {
e1.printStackTrace();
}
Is throwing NPE. :(
But
System.out.println(getClass().getProtectionDomain().getCodeSource().getLocation().getPath());
is showing client.jar only. Not the absolute path. It is inside a Jar.