RootLoader (Groovy 5.0.0)

Package: org.codehaus.groovy.tools

## [Java] Class RootLoader

- org.codehaus.groovy.tools.RootLoader

-     public class RootLoader
      extends URLClassLoader

  This ClassLoader should be used as root of class loaders. Any RootLoader does have its own classpath. When searching for a class or resource this classpath will be used. Parent Classloaders are ignored first. If a class or resource can't be found in the classpath of the RootLoader, then parent is checked.

  Note: this is very against the normal behavior of classloaders. Normal is to first check parent and then look in the resources you gave this classloader.

  It's possible to add urls to the classpath at runtime through addURL(URL).

  Why using RootLoader? If you have to load classes with multiple classloaders and a classloader does know a class which depends on a class only a child of this loader does know, then you won't be able to load the class. To load the class the child is not allowed to redirect its search for the class to the parent first. That way the child can load the class. If the child does not have all classes to do this, this fails of course.

  For example:

             parentLoader   (has classpath: a.jar;c.jar)
                 |
                 |
             childLoader    (has classpath: a.jar;b.jar;c.jar)

  class C (from c.jar) extends B (from b.jar) childLoader.find("C")

       --> parentLoader does know C.class, try to load it
       --> to load C.class it has to load B.class
       --> parentLoader is unable to find B.class in a.jar or c.jar
       --> NoClassDefFoundException!

  if childLoader had tried to load the class by itself, there would be no problem. Changing childLoader to be a RootLoader instance will solve that problem.

- - ### Constructor Summary

    Constructors
    Constructor and description
    `RootLoader(ClassLoader parent)` Constructs a `RootLoader` without classpath.
    `RootLoader(URL[] urls, ClassLoader parent)` Constructs a `RootLoader` with a parent loader and an array of URLs as its classpath.
    `RootLoader(LoaderConfiguration lc)` Constructs a `RootLoader` with a LoaderConfiguration object which holds the classpath.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public void` | `addURL(URL url)` {@inheritDoc}
    `` | `protected Class<?>` | `findClass(String name)` {@inheritDoc}
    `` | `public URL` | `getResource(String name)` {@inheritDoc}
    `` | `protected Class<?>` | `loadClass(String name, boolean resolve)` {@inheritDoc}

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class URLClassLoader` | `clearAssertionStatus, close, equals, findResource, findResources, getClass, getDefinedPackage, getDefinedPackages, getName, getParent, getPlatformClassLoader, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getURLs, getUnnamedModule, hashCode, isRegisteredAsParallelCapable, loadClass, newInstance, newInstance, notify, notifyAll, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### public RootLoader(ClassLoader parent)

      Constructs a `RootLoader` without classpath.

      Parameters:
        `parent` - the parent Loader

    - #### public RootLoader(URL[] urls, ClassLoader parent)

      Constructs a `RootLoader` with a parent loader and an array of URLs as its classpath.

    - #### public RootLoader(LoaderConfiguration lc)

      Constructs a `RootLoader` with a LoaderConfiguration object which holds the classpath.

  - ### Method Detail

    - #### @Override
      public void addURL(URL url)

      {@inheritDoc}

    - #### @Override
      protected Class<?> findClass(String name)

      {@inheritDoc}

    - #### @Override
      public URL getResource(String name)

      {@inheritDoc}

    - #### @Override
      protected Class<?> loadClass(String name, boolean resolve)

      {@inheritDoc}