SplitClassLoader (Apache Ant API)
Description: declaration: package: org.apache.tools.ant.util, class: SplitClassLoader

# Class SplitClassLoader

java.lang.Object
java.lang.ClassLoader
org.apache.tools.ant.AntClassLoader
org.apache.tools.ant.util.SplitClassLoader

All Implemented Interfaces:
  `Closeable, AutoCloseable, EventListener, BuildListener, SubBuildListener`

public final class SplitClassLoader extends AntClassLoader
Specialized classloader for tasks that need finer grained control over which classes are to be loaded via Ant's classloader and which should not even if they are available.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SplitClassLoader(ClassLoader parent, Path path, Project project, String[] splitClasses)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected Class<?>`
  `loadClass(String classname, boolean resolve)`
  Loads a class with this class loader.

  ### Methods inherited from class AntClassLoader

  `addJavaLibraries, addLoaderPackageRoot, addPathComponent, addPathElement, addPathFile, addSystemPackageRoot, buildFinished, buildStarted, cleanup, close, defineClassFromData, definePackage, definePackage, findClass, findResource, findResources, findResources, forceLoadClass, forceLoadSystemClass, getClasspath, getConfiguredParent, getNamedResources, getResource, getResourceAsStream, getResources, getResourceURL, initializeClass, isInPath, log, messageLogged, newAntClassLoader, resetThreadContextLoader, setClassPath, setIsolated, setParent, setParentFirst, setProject, setThreadContextLoader, subBuildFinished, subBuildStarted, targetFinished, targetStarted, taskFinished, taskStarted, toString`
  Modifier and Type
  Method
  Description
  `void`
  `addJavaLibraries()`
  add any libraries that come with different java versions here
  `void`
  `addLoaderPackageRoot(String packageRoot)`
  Adds a package root to the list of packages which must be loaded using this loader.
  `void`
  `addPathComponent(File file)`
  Add a path component.
  `void`
  `addPathElement(String pathElement)`
  Adds an element to the classpath to be searched.
  `protected void`
  `addPathFile(File pathComponent)`
  Add a file to the path.
  `void`
  `addSystemPackageRoot(String packageRoot)`
  Adds a package root to the list of packages which must be loaded on the parent loader.
  `void`
  `buildFinished(BuildEvent event)`
  Cleans up any resources held by this classloader at the end of a build.
  `void`
  `buildStarted(BuildEvent event)`
  Empty implementation to satisfy the BuildListener interface.
  `void`
  `cleanup()`
  Cleans up any resources held by this classloader.
  `void`
  `close()`
  `protected Class<?>`
  `defineClassFromData(File container, byte[] classData, String classname)`
  Define a class given its bytes
  `protected void`
  `definePackage(File container, String className)`
  Define the package information associated with a class.
  `protected void`
  `definePackage(File container, String packageName, Manifest manifest)`
  Define the package information when the class comes from a jar with a manifest
  `Class<?>`
  `findClass(String name)`
  Searches for and load a class on the classpath of this class loader.
  `protected URL`
  `findResource(String name)`
  Finds the resource with the given name.
  `protected Enumeration<URL>`
  `findResources(String name)`
  Returns an enumeration of URLs representing all the resources with the given name by searching the class loader's classpath.
  `protected Enumeration<URL>`
  `findResources(String name, boolean skipParent)`
  Returns an enumeration of URLs representing all the resources with the given name by searching the class loader's classpath.
  `Class<?>`
  `forceLoadClass(String classname)`
  Loads a class through this class loader even if that class is available on the parent classpath.
  `Class<?>`
  `forceLoadSystemClass(String classname)`
  Loads a class through this class loader but defer to the parent class loader.
  `String`
  `getClasspath()`
  Returns the classpath this classloader will consult.
  `ClassLoader`
  `getConfiguredParent()`
  Gets the parent as has been specified in the constructor or via setParent.
  `Enumeration<URL>`
  `getNamedResources(String name)`
  Finds all the resources with the given name.
  `URL`
  `getResource(String name)`
  Finds the resource with the given name.
  `InputStream`
  `getResourceAsStream(String name)`
  Returns a stream to read the requested resource name.
  `Enumeration<URL>`
  `getResources(String name)`
  `protected URL`
  `getResourceURL(File file, String resourceName)`
  Returns the URL of a given resource in the given file which may either be a directory or a zip file.
  `static void`
  `initializeClass(Class<?> theClass)`
  Deprecated.
  since 1.6.x.
  `protected boolean`
  `isInPath(File component)`
  Indicate if the given file is in this loader's path
  `protected void`
  `log(String message, int priority)`
  Logs a message through the project object if one has been provided.
  `void`
  `messageLogged(BuildEvent event)`
  Empty implementation to satisfy the BuildListener interface.
  `static AntClassLoader`
  `newAntClassLoader(ClassLoader parent, Project project, Path path, boolean parentFirst)`
  Factory method
  `void`
  `resetThreadContextLoader()`
  Resets the current thread's context loader to its original value.
  `void`
  `setClassPath(Path classpath)`
  Set the classpath to search for classes to load.
  `void`
  `setIsolated(boolean isolated)`
  Sets whether this classloader should run in isolated mode.
  `void`
  `setParent(ClassLoader parent)`
  Set the parent for this class loader.
  `void`
  `setParentFirst(boolean parentFirst)`
  Control whether class lookup is delegated to the parent loader first or after this loader.
  `void`
  `setProject(Project project)`
  Set the project associated with this class loader
  `void`
  `setThreadContextLoader()`
  Sets the current thread's context loader to this classloader, storing the current loader value for later resetting.
  `void`
  `subBuildFinished(BuildEvent event)`
  Cleans up any resources held by this classloader at the end of a subbuild if it has been created for the subbuild's project instance.
  `void`
  `subBuildStarted(BuildEvent event)`
  Empty implementation to satisfy the BuildListener interface.
  `void`
  `targetFinished(BuildEvent event)`
  Empty implementation to satisfy the BuildListener interface.
  `void`
  `targetStarted(BuildEvent event)`
  Empty implementation to satisfy the BuildListener interface.
  `void`
  `taskFinished(BuildEvent event)`
  Empty implementation to satisfy the BuildListener interface.
  `void`
  `taskStarted(BuildEvent event)`
  Empty implementation to satisfy the BuildListener interface.
  `String`
  `toString()`
  Returns a `String` representing this loader.

  ### Methods inherited from class ClassLoader

  `clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners`

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### SplitClassLoader

    public SplitClassLoader(ClassLoader parent, Path path, Project project, String[] splitClasses)
    Parameters:
      `parent` - ClassLoader
      `path` - Path
      `project` - Project
      `splitClasses` - classes contained herein will not be loaded via Ant's classloader

- ## Method Details

  - ### loadClass

    protected Class<?> loadClass(String classname, boolean resolve) throws ClassNotFoundException
    Description copied from class: `AntClassLoader`
    Loads a class with this class loader. This class attempts to load the class in an order determined by whether or not the class matches the system/loader package lists, with the loader package list taking priority. If the classloader is in isolated mode, failure to load the class in this loader will result in a ClassNotFoundException.
    Overrides:
      `loadClass` in class `AntClassLoader`
    Parameters:
      `classname` - The name of the class to be loaded. Must not be `null`.
      `resolve` - `true` if all classes upon which this class depends are to be loaded.
    Returns:
      the required Class object
    Throws:
      `ClassNotFoundException` - if the requested class does not exist on the system classpath (when not in isolated mode) or this loader's classpath.