PackageCrawler latest version

This commit is contained in:
Jakob Herrmann 2017-04-06 16:16:47 +02:00
parent 42010c5859
commit dad08cfa46

View File

@ -12,7 +12,7 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Set; import java.util.Set;
import java.lang.InterruptedException;
/** /**
* Hilft beim Durchsuchen von Packages * Hilft beim Durchsuchen von Packages
* Benutzt die Reflections-Library (https://github.com/ronmamo/reflections) * Benutzt die Reflections-Library (https://github.com/ronmamo/reflections)
@ -20,10 +20,11 @@ import java.util.Set;
*/ */
public class PackageCrawler { public class PackageCrawler {
public static Set<Class<?>> getClassesInPackage(String packageName) { public static Set<Class<?>> getClassesInPackage(String packageName){
List<ClassLoader> classLoadersList = new LinkedList<ClassLoader>(); List<ClassLoader> classLoadersList = new LinkedList<ClassLoader>();
classLoadersList.add(ClasspathHelper.contextClassLoader()); classLoadersList.add(Thread.currentThread().getContextClassLoader());
classLoadersList.add(ClasspathHelper.staticClassLoader()); classLoadersList.add(ClasspathHelper.staticClassLoader());
classLoadersList.add(Thread.currentThread().getContextClassLoader().getParent());
Reflections reflections = new Reflections(new ConfigurationBuilder() Reflections reflections = new Reflections(new ConfigurationBuilder()
.setScanners(new SubTypesScanner(false /* don't exclude Object.class */), new ResourcesScanner()) .setScanners(new SubTypesScanner(false /* don't exclude Object.class */), new ResourcesScanner())