Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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