Class LoaderUtil

    • Field Detail

      • forceTcclOnly

        protected static Boolean forceTcclOnly
    • Method Detail

      • getClassLoader

        public static ClassLoader getClassLoader()
        Returns the ClassLoader to use.
        Returns:
        the ClassLoader.
      • getThreadContextClassLoader

        public static ClassLoader getThreadContextClassLoader()
        Gets the current Thread ClassLoader. Returns the system ClassLoader if the TCCL is null. If the system ClassLoader is null as well, then the ClassLoader for this class is returned. If running with a SecurityManager that does not allow access to the Thread ClassLoader or system ClassLoader, then the ClassLoader for this class is returned.
        Returns:
        the current ThreadContextClassLoader.
      • getClassLoaders

        public static ClassLoader[] getClassLoaders()
      • isClassAvailable

        public static boolean isClassAvailable​(String className)
        Determines if a named Class can be loaded or not.
        Parameters:
        className - The class name.
        Returns:
        true if the class could be found or false otherwise.
        Since:
        2.7
      • loadClass

        public static Class<?> loadClass​(String className)
                                  throws ClassNotFoundException
        Loads a class by name. This method respects the Log4j property. If this property is specified and set to anything besides false, then this class's ClassLoader will be used as specified by Class.forName(String).
        Parameters:
        className - The class name.
        Returns:
        the Class for the given name.
        Throws:
        ClassNotFoundException - if the specified class name could not be found
        Since:
        2.1
      • findResources

        public static Collection<URL> findResources​(String resource)
        Finds classpath resources.
        Parameters:
        resource - the name of the resource to find.
        Returns:
        a Collection of URLs matching the resource name. If no resources could be found, then this will be empty.
        Since:
        2.1
      • findResources

        public static Collection<URL> findResources​(String resource,
                                                    boolean useTccl)
      • findUrlResources

        public static Collection<LoaderUtil.UrlResource> findUrlResources​(String resource,
                                                                          boolean useTccl)
        This method will only find resources that follow the JPMS rules for encapsulation. Resources on the class path should be found as normal along with resources with no package name in all modules. Resources within packages in modules must declare those resources open to org.apache.logging.log4j.
        Parameters:
        resource - The resource to locate.
        Returns:
        The located resources.