Skip to content

Instantly share code, notes, and snippets.

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) {
return null;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.