How do I get the directory that the currently executing jar file is in?

jar, java

Solution

Not a perfect solution but this will return class code base’s location:

getClass().getProtectionDomain().getCodeSource().getLocation()

Problem

I'm running a jar file in various locations and I'm trying to figure out how to get the location of the jar file that is running.

Original source

Related problems