Skip to content

Instantly share code, notes, and snippets.

@irof
Created December 7, 2015 14:43
Show Gist options
  • Save irof/a5b257c6c3ead2052ddf to your computer and use it in GitHub Desktop.
Save irof/a5b257c6c3ead2052ddf to your computer and use it in GitHub Desktop.
Springさんのクラススキャンのところを抜粋してみた
import java.net.JarURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.jar.JarFile;
public class Main {
public static void main(String[] args) throws Exception {
Enumeration<URL> systemResources = ClassLoader.getSystemResources("org/springframework");
while (systemResources.hasMoreElements()) {
URL url = systemResources.nextElement();
// とりあえずjarの所在を出してみる
System.out.println("*** jar: " + url);
URLConnection urlConnection = url.openConnection();
JarURLConnection jarCon = (JarURLConnection) urlConnection;
JarFile jarFile = jarCon.getJarFile();
// 中に入ってるclassを書き並べてみる
Collections.list(jarFile.entries()).stream()
.filter(entry -> entry.getName().endsWith(".class"))
.forEach(System.out::println);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment