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:\Users\Kevin\Desktop/server/Server
while the JAR file is located at
C:\Users\Kevin\Desktop
I also tried doing
return new file(Server.class.getProtectionDomain().getCodeSource().getLocation().getPath());
But that returns:
C:\Users\Kevin\Desktop\server.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?