Class ClasspathHelper


  • public abstract class ClasspathHelper
    extends Object
    Helper methods for working with the classpath.
    • Constructor Detail

      • ClasspathHelper

        public ClasspathHelper()
    • Method Detail

      • contextClassLoader

        public static ClassLoader contextClassLoader()
        Gets the current thread context class loader. Thread.currentThread().getContextClassLoader().
        Returns:
        the context class loader, may be null
      • staticClassLoader

        public static ClassLoader staticClassLoader()
        Gets the class loader of this library. Reflections.class.getClassLoader().
        Returns:
        the static library class loader, may be null
      • forJavaClassPath

        public static Collection<URL> forJavaClassPath()
        Returns a distinct collection of URLs based on the java.class.path system property.

        This finds the URLs using the java.class.path system property.

        The returned collection of URLs retains the classpath order.

        Returns:
        the collection of URLs, not null
      • forWebInfLib

        public static Collection<URL> forWebInfLib​(javax.servlet.ServletContext servletContext)
        Returns a distinct collection of URLs based on the WEB-INF/lib folder.

        This finds the URLs using the ServletContext.

        The returned URLs retains the order of the given classLoaders.

        Returns:
        the collection of URLs, not null
      • forWebInfClasses

        public static URL forWebInfClasses​(javax.servlet.ServletContext servletContext)
        Returns the URL of the WEB-INF/classes folder.

        This finds the URLs using the ServletContext.

        Returns:
        the collection of URLs, not null
      • forManifest

        public static Collection<URL> forManifest()
        Returns a distinct collection of URLs based on URLs derived from class loaders expanded with Manifest information.

        The MANIFEST.MF file can contain a Class-Path entry that defines additional jar files to be included on the classpath. This method finds the jar files using the contextClassLoader() and staticClassLoader(), before searching for any additional manifest classpaths.

        Returns:
        the collection of URLs, not null
      • forManifest

        public static Collection<URL> forManifest​(URL url)
        Returns a distinct collection of URLs from a single URL based on the Manifest information.

        The MANIFEST.MF file can contain a Class-Path entry that defines additional jar files to be included on the classpath. This method takes a single URL, tries to resolve it as a jar file, and if so, adds any additional manifest classpaths. The returned collection of URLs will always contain the input URL.

        Returns:
        the collection of URLs, not null
      • forManifest

        public static Collection<URL> forManifest​(Iterable<URL> urls)
        Returns a distinct collection of URLs by expanding the specified URLs with Manifest information.

        The MANIFEST.MF file can contain a Class-Path entry that defines additional jar files to be included on the classpath. This method takes each URL in turn, tries to resolve it as a jar file, and if so, adds any additional manifest classpaths. The returned collection of URLs will always contain all the input URLs.

        The returned URLs retains the input order.

        Returns:
        the collection of URLs, not null
      • cleanPath

        public static String cleanPath​(URL url)
        Cleans the URL.
        Parameters:
        url - the URL to clean, not null
        Returns:
        the path, not null