Skip to content

Instantly share code, notes, and snippets.

@nilsmagnus
Created February 16, 2013 09:40
Show Gist options
  • Save nilsmagnus/4966264 to your computer and use it in GitHub Desktop.
Save nilsmagnus/4966264 to your computer and use it in GitHub Desktop.
Finding the jar of a specific class.
private String getPath(Class cls) {
String cn = cls.getName();
String rn = cn.replace('.', '/') + ".class";
String path = getClass().getClassLoader().getResource(rn).getPath();
int ix = path.indexOf("!");
if(ix >= 0) {
return path.substring(0, ix);
} else {
return path;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment