Skip to content

Instantly share code, notes, and snippets.

@madan712
Last active December 10, 2015 22:28
Show Gist options
  • Save madan712/4502423 to your computer and use it in GitHub Desktop.
Save madan712/4502423 to your computer and use it in GitHub Desktop.
Java - How to find which jar file is referring for a specific class
import java.util.Properties;
public class CheckJar {
public static void main(String[] args) {
Properties prop = System.getProperties();
System.out.println("Classpath : " + prop.getProperty("java.class.path"));
System.out.println("JVM name : "+ prop.getProperty("java.vm.specification.name"));
try {
Class clazz = Class.forName("javax.mail.Transport");//provide your class name
if (clazz == null
|| clazz.getProtectionDomain() == null
|| clazz.getProtectionDomain().getCodeSource() == null
|| clazz.getProtectionDomain().getCodeSource()
.getLocation() == null) {
System.out.println("Not found!");
} else {
System.out.println(clazz.getProtectionDomain().getCodeSource()
.getLocation().toString());
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment