Last active
August 2, 2021 08:25
-
-
Save zasadnyy/126ae19718b547ee3b9e to your computer and use it in GitHub Desktop.
Print all files and folders added to java classpath
This file contains 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
// 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 + "\"" | |
} | |
} |
Can somebody post a snipped that works for AppClassLoader or for any class loader? I am a java novice.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
//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