Skip to content

Instantly share code, notes, and snippets.

@zasadnyy zasadnyy/print class path
Last active Nov 23, 2018

Embed
What would you like to do?
Print all files and folders added to java classpath
// JAVA
public static void main(String[] args)
{
ClassLoader cl = ClassLoader.getSystemClassLoader();
URL[] urls = ((URLClassLoader)cl).getURLs();
for(URL url: urls){
System.out.println(url.getFile());
}
}
// GRADLE
testClasses.doFirst {
println "Test classpath is:- "
sourceSets.test.runtimeClasspath.getFiles().each { file ->
println "file: \"" + file + "\""
}
}
@Masterxilo

This comment has been minimized.

Copy link

commented Nov 23, 2018

//Exception in thread "main" java.lang.ClassCastException: java.base/jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to java.base/java.net.URLClassLoader
// at ShowClasspath.main(ShowClasspath.java:13)

There is no guarantee that the class loader is a urlclassloader

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.