Created
December 7, 2015 14:43
-
-
Save irof/a5b257c6c3ead2052ddf to your computer and use it in GitHub Desktop.
Springさんのクラススキャンのところを抜粋してみた
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
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