Is there a programmatically way to get the complete list of all jar in
the classpath ?
This is one way to print out the current project classpath:
ClassLoader cl = ClassLoader.getSystemClassLoader();
java.net.URL[] urls = ((java.net.URLClassLoader)cl).getURLs();
for (java.net.URL url: urls) {
System.out.println(url.getFile());
}
If you need to determine which jar a class is loaded from:
Class klass = ClassInTrouble.class;
CodeSource source = klass.getProtectionDomain().getCodeSource();
System.out.println(source == null ? klass : source.getLocation());
You can also get a list of all classes loaded in the JVM, if that's useful.