Last active
December 10, 2015 22:28
-
-
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
This file contains hidden or 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
| 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