List of utility methods to do Class from Package
List | getClasses(String packageName) Locates all classes in given package String path = packageName.replace('.', '/'); List<URL> dirs = getDirectories(path); ArrayList<Class<?>> classes = new ArrayList<Class<?>>(); ClassLoader loader = URLClassLoader.newInstance(dirs.toArray(new URL[0]), Thread.currentThread().getContextClassLoader()); for (URL directory : dirs) { String resource = directory.getPath().replace("/" + path + "/", ""); if (resource.endsWith(".jar")) { ... |
Class[] | getClasses(String packageName) Returns an array of classes in a specified package try { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); assert classLoader != null; String path = packageName.replace('.', '/'); Enumeration<URL> resources = classLoader.getResources(path); List<File> dirs = new ArrayList<File>(); while (resources.hasMoreElements()) { URL resource = resources.nextElement(); ... |
Iterable | getClasses(String packageName) get Classes ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); String path = packageName.replace('.', '/'); Enumeration<URL> resources = classLoader.getResources(path); List<File> dirs = new ArrayList<File>(); while (resources.hasMoreElements()) { URL resource = resources.nextElement(); dirs.add(new File(resource.getFile())); List<Class> classes = new ArrayList<Class>(); for (File directory : dirs) { classes.addAll(findClasses(directory, packageName)); return classes; |
Class[] | getClasses(String packageName) get Classes ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); assert classLoader != null; String path = packageName.replace('.', '/'); Enumeration<URL> resources = classLoader.getResources(path); List<File> dirs = new ArrayList<File>(); while (resources.hasMoreElements()) { URL resource = resources.nextElement(); dirs.add(new File(java.net.URLDecoder.decode(resource.getFile().toString()))); ... |
List | getClasses(String packageName) get Classes ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); String path = packageName.replace(".", "/"); Enumeration<URL> resources = null; try { resources = classLoader.getResources(path); } catch (IOException e) { e.printStackTrace(); List<File> dirs = new ArrayList<>(); if (resources != null) { while (resources.hasMoreElements()) { URL resource = resources.nextElement(); dirs.add(new File(resource.getFile())); ArrayList<Class> classes = new ArrayList<>(); for (File directory : dirs) { classes.addAll(findClass(directory, packageName)); return classes; |
Class[] | getClasses(String packageName) Returns all classes from specified package. ArrayList<Class> classes = new ArrayList<Class>(); File directory = null; try { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader == null) { throw new ClassNotFoundException("Can't get class loader."); String path = packageName.replace('.', '/'); ... |
List | getClasses(String packageName) Scans all classes accessible from the context class loader which belong to the given package and subpackages. ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); assert classLoader != null; String path = packageName.replace('.', '/'); Enumeration<URL> resources = classLoader.getResources(path); List<File> dirs = new ArrayList<File>(); while (resources.hasMoreElements()) { URL resource = resources.nextElement(); String fileName = resource.getFile(); ... |
Class>[] | getClasses(String packageName) Scans all classes accessible from the context class loader which belong to the given package and subpackages. ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); assert classLoader != null; String path = packageName.replace('.', '/'); Enumeration<URL> resources = classLoader.getResources(path); List<File> dirs = new ArrayList<File>(); while (resources.hasMoreElements()) { URL resource = resources.nextElement(); dirs.add(new File(resource.getFile())); ... |
ArrayList | getClasses(String packageName, Class Scans all classes accessible from the context class loader which belong to the given package and subpackages. ArrayList<Class<? extends T>> result = new ArrayList<Class<? extends T>>(); ArrayList<Class<?>> classes = new ArrayList<Class<?>>(); try { classes = getClasses(packageName); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); ... |
List | getClasses(String pckgname) get Classes List<Class> classes = new ArrayList<Class>(); ClassLoader cld = Thread.currentThread().getContextClassLoader(); String path = '/' + pckgname.replace('.', '/'); URL resource = cld.getResource(path); File directory = new File(resource.getFile()); if (directory.exists()) { String[] files = directory.list(); for (int i = 0; i < files.length; i++) { ... |