I'm trying to get the location a Runnable JAR file is run from. I tried doing
try {
String path = new java.io.File(".").getCanonicalPath();
} catch (IOException e) {
e.printStackTrace();
}
But that returns:
C:UsersKevinDesktop/server/Server
while the JAR file is located at
C:UsersKevinDesktop
I also tried doing
return new file(Server.class.getProtectionDomain().getCodeSource().getLocation().getPath());
But that returns:
C:UsersKevinDesktopserver.jar/server/Server
So basicly I want the path of the JAR file without the filename and not the ClassPath.
Any way of doing this?
See Question&Answers more detail:os