org.reflections.util
Class ClasspathHelper

java.lang.Object
  extended by org.reflections.util.ClasspathHelper

public abstract class ClasspathHelper
extends Object

Some classpath convenient methods


Constructor Summary
ClasspathHelper()
           
 
Method Summary
static ClassLoader[] classLoaders(ClassLoader... classLoaders)
          returns given classLoaders, if not null, otherwise defaults to both contextClassLoader() and staticClassLoader()
static String cleanPath(URL url)
           
static ClassLoader contextClassLoader()
          returns Thread.currentThread().getContextClassLoader()
static URL forClass(Class<?> aClass, ClassLoader... classLoaders)
          returns the url that contains the given class, using ClassLoader.getResource(String)
static Set<URL> forClassLoader()
          returns urls using URLClassLoader.getURLs() up the default classloaders parent hierarchy
static Set<URL> forClassLoader(ClassLoader... classLoaders)
          returns urls using URLClassLoader.getURLs() up the classloader parent hierarchy
static Set<URL> forJavaClassPath()
          returns urls using java.class.path system property
static Set<URL> forManifest()
          return urls that are in the current class path.
static Set<URL> forManifest(Iterable<URL> urls)
          get the urls that are specified in the manifest of the given urls.
static Set<URL> forManifest(URL url)
          get the urls that are specified in the manifest of the given url for a jar file.
static Set<URL> forPackage(String name, ClassLoader... classLoaders)
          returns urls with resources of package starting with given name, using ClassLoader.getResources(String)
static Set<URL> forResource(String resourceName, ClassLoader... classLoaders)
          returns urls with resources of given @{code resourceName}, using ClassLoader.getResources(String)
static URL forWebInfClasses(javax.servlet.ServletContext servletContext)
          returns url using ServletContext in resource path WEB-INF/classes
static Set<URL> forWebInfLib(javax.servlet.ServletContext servletContext)
          returns urls using ServletContext in resource path WEB-INF/lib
static ClassLoader staticClassLoader()
          returns Reflections.class.getClassLoader()
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClasspathHelper

public ClasspathHelper()
Method Detail

contextClassLoader

public static ClassLoader contextClassLoader()
returns Thread.currentThread().getContextClassLoader()


staticClassLoader

public static ClassLoader staticClassLoader()
returns Reflections.class.getClassLoader()


classLoaders

public static ClassLoader[] classLoaders(ClassLoader... classLoaders)
returns given classLoaders, if not null, otherwise defaults to both contextClassLoader() and staticClassLoader()


forPackage

public static Set<URL> forPackage(String name,
                                  ClassLoader... classLoaders)
returns urls with resources of package starting with given name, using ClassLoader.getResources(String)

that is, forPackage("org.reflections") effectively returns urls from classpath with packages starting with org.reflections

if optional ClassLoaders are not specified, then both contextClassLoader() and staticClassLoader() are used for ClassLoader.getResources(String)


forResource

public static Set<URL> forResource(String resourceName,
                                   ClassLoader... classLoaders)
returns urls with resources of given @{code resourceName}, using ClassLoader.getResources(String)


forClass

public static URL forClass(Class<?> aClass,
                           ClassLoader... classLoaders)
returns the url that contains the given class, using ClassLoader.getResource(String)

if optional ClassLoaders are not specified, then either contextClassLoader() or staticClassLoader() are used for ClassLoader.getResources(String)


forClassLoader

public static Set<URL> forClassLoader()
returns urls using URLClassLoader.getURLs() up the default classloaders parent hierarchy

using classLoaders(ClassLoader...) to get default classloaders


forClassLoader

public static Set<URL> forClassLoader(ClassLoader... classLoaders)
returns urls using URLClassLoader.getURLs() up the classloader parent hierarchy

if optional ClassLoaders are not specified, then both contextClassLoader() and staticClassLoader() are used for ClassLoader.getResources(String)


forJavaClassPath

public static Set<URL> forJavaClassPath()
returns urls using java.class.path system property


forWebInfLib

public static Set<URL> forWebInfLib(javax.servlet.ServletContext servletContext)
returns urls using ServletContext in resource path WEB-INF/lib


forWebInfClasses

public static URL forWebInfClasses(javax.servlet.ServletContext servletContext)
returns url using ServletContext in resource path WEB-INF/classes


forManifest

public static Set<URL> forManifest()
return urls that are in the current class path. attempts to load the jar manifest, if any, and adds to the result any dependencies it finds.


forManifest

public static Set<URL> forManifest(URL url)
get the urls that are specified in the manifest of the given url for a jar file. attempts to load the jar manifest, if any, and adds to the result any dependencies it finds.


forManifest

public static Set<URL> forManifest(Iterable<URL> urls)
get the urls that are specified in the manifest of the given urls. attempts to load the jar manifest, if any, and adds to the result any dependencies it finds.


cleanPath

public static String cleanPath(URL url)


Copyright © 2013. All Rights Reserved.