Skip to content

Instantly share code, notes, and snippets.

@kofemann
Created October 9, 2013 10:40
Show Gist options
  • Save kofemann/6899329 to your computer and use it in GitHub Desktop.
Save kofemann/6899329 to your computer and use it in GitHub Desktop.
find from which jar some class is taken. Example: $ java -cp .:/$CLASSPATH find_jar org.slf4j.Logger file:/xxxx/classes/slf4j-api-1.7.5.jar $
import java.security.CodeSource;
public class find_jar {
public static void main(String[] args) throws Exception {
if (args.length != 1 ) {
System.err.println("Usage: find <class name>");
System.exit(1);
}
Class c = Class.forName(args[0]);
CodeSource codeSource = c.getProtectionDomain().getCodeSource();
System.out.println(codeSource.getLocation());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment