Skip to content

Instantly share code, notes, and snippets.

@RayanFar
Created September 28, 2017 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RayanFar/c594b8ceaea7c1a8da479493c8f040a9 to your computer and use it in GitHub Desktop.
Save RayanFar/c594b8ceaea7c1a8da479493c8f040a9 to your computer and use it in GitHub Desktop.
public static String path(Class clazz) {
try {
File tmp = new File(clazz.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
String ext = tmp.getName();
if (ext.contains(".jar")) {
String p = tmp.toString();
p = p.substring(0, p.lastIndexOf(File.separator));
return p + File.separator;
} else {
return p;
}
} catch (URISyntaxException e) {
e.printStackTrace();
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment