Created
February 16, 2013 09:40
-
-
Save nilsmagnus/4966264 to your computer and use it in GitHub Desktop.
Finding the jar of a specific class.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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