/** * Scans the context classloader and the classloader of this class for all resources that have a * specified name, and returns a list of {@link ClassLoaderResource} objects for the found * resources. * * <p>The returned list contains the URLs of the resources, and for each resource the highest * classloader in the classloader hierarchy on which the resource was found. * * @param resource the resource names * @return a list of resources with the specified name; the list is empty if no resources have * been found for the name * @see ClassLoader#getResources(String) */ public static List<ClassLoaderResource> getClassLoaderResources(String resource) { Map<URL, ClassLoaderResource> resources = new LinkedHashMap<URL, ClassLoaderResource>(); collectResources(resource, JRLoader.class.getClassLoader(), resources); // TODO check if the classloader is the same collectResources(resource, Thread.currentThread().getContextClassLoader(), resources); return new ArrayList<ClassLoaderResource>(resources.values()); }
/** * Scans the context classloader and the classloader of this class for all resources that have a * specified name, and returns a list of {@link URL}s for the found resources. * * @param resource the resource names * @return a list of {@link URL}s of resources with the specified name; the list is empty if no * resources have been found for the name * @see ClassLoader#getResources(String) */ public static List<URL> getResources(String resource) { // skip duplicated resources Set<URL> resources = new LinkedHashSet<URL>(); collectResources(resource, JRLoader.class.getClassLoader(), resources); collectResources(resource, Thread.currentThread().getContextClassLoader(), resources); return new ArrayList<URL>(resources); }