The following code snippet will do this for you:
final File f = new File(MyClass.class.getProtectionDomain().getCodeSource().getLocation().getPath());
replace MyClass with your main class
The resulting File object f represents the .jar file that was executed. You can use this object to get the parent to find the directory that the .jar is in.