Save This Page
Home » apache-ant-1.8.1 » org.apache.tools » ant » [javadoc | source]
org.apache.tools.ant
public class: AntClassLoader [javadoc | source]
java.lang.Object
   java.lang.ClassLoader
      org.apache.tools.ant.AntClassLoader

All Implemented Interfaces:
    SubBuildListener

Direct Known Subclasses:
    AntClassLoader5, AntClassLoader2, SplitClassLoader

Used to load classes within ant with a different classpath from that used to start ant. Note that it is possible to force a class into this loader even when that class is on the system classpath by using the forceLoadClass method. Any subsequent classes loaded by that class will then use this loader rather than the system class loader.

Note that this classloader has a feature to allow loading in reverse order and for "isolation". Due to the fact that a number of methods in java.lang.ClassLoader are final (at least in java 1.4 getResources) this means that the class has to fake the given parent.

Fields inherited from java.lang.ClassLoader:
nocerts,  classAssertionStatus
Constructor:
 public AntClassLoader() 
 public AntClassLoader(Project project,
    Path classpath) 
    Creates a classloader for the given project using the classpath given.
    Parameters:
    project - The project to which this classloader is to belong. Must not be null.
    classpath - The classpath to use to load the classes. This is combined with the system classpath in a manner determined by the value of ${build.sysclasspath}. May be null, in which case no path elements are set up to start with.
 public AntClassLoader(ClassLoader parent,
    boolean parentFirst) 
    Creates an empty class loader. The classloader should be configured with path elements to specify where the loader is to look for classes.
    Parameters:
    parent - The parent classloader to which unsatisfied loading attempts are delegated. May be null, in which case the classloader which loaded this class is used as the parent.
    parentFirst - If true, indicates that the parent classloader should be consulted before trying to load the a class through this loader.
 public AntClassLoader(ClassLoader parent,
    Project project,
    Path classpath) 
    Create an Ant ClassLoader for a given project, with a parent classloader and an initial classpath.
    Parameters:
    parent - the parent for this classloader.
    project - The project to which this classloader is to belong.
    classpath - The classpath to use to load classes.
    since: Ant - 1.7.
 public AntClassLoader(Project project,
    Path classpath,
    boolean parentFirst) 
    Creates a classloader for the given project using the classpath given.
    Parameters:
    project - The project to which this classloader is to belong. Must not be null.
    classpath - The classpath to use to load the classes. May be null, in which case no path elements are set up to start with.
    parentFirst - If true, indicates that the parent classloader should be consulted before trying to load the a class through this loader.
 public AntClassLoader(ClassLoader parent,
    Project project,
    Path classpath,
    boolean parentFirst) 
    Creates a classloader for the given project using the classpath given.
    Parameters:
    parent - The parent classloader to which unsatisfied loading attempts are delegated. May be null, in which case the classloader which loaded this class is used as the parent.
    project - The project to which this classloader is to belong. Must not be null.
    classpath - the classpath to use to load the classes. May be null, in which case no path elements are set up to start with.
    parentFirst - If true, indicates that the parent classloader should be consulted before trying to load the a class through this loader.
Method from org.apache.tools.ant.AntClassLoader Summary:
addJavaLibraries,   addLoaderPackageRoot,   addPathComponent,   addPathElement,   addPathFile,   addSystemPackageRoot,   buildFinished,   buildStarted,   cleanup,   defineClassFromData,   definePackage,   definePackage,   findClass,   findResources,   findResources,   forceLoadClass,   forceLoadSystemClass,   getClasspath,   getConfiguredParent,   getNamedResources,   getResource,   getResourceAsStream,   getResourceURL,   initializeClass,   isInPath,   loadClass,   log,   messageLogged,   newAntClassLoader,   resetThreadContextLoader,   setClassPath,   setIsolated,   setParent,   setParentFirst,   setProject,   setThreadContextLoader,   subBuildFinished,   subBuildStarted,   targetFinished,   targetStarted,   taskFinished,   taskStarted,   toString
Methods from java.lang.ClassLoader:
access$000,   access$100,   addClass,   clearAssertionStatus,   defineClass,   defineClass,   defineClass,   defineClass,   definePackage,   desiredAssertionStatus,   findClass,   findLibrary,   findLoadedClass,   findNative,   findResource,   findResources,   findSystemClass,   getBootstrapClassPath,   getCallerClassLoader,   getPackage,   getPackages,   getParent,   getResource,   getResourceAsStream,   getResources,   getSystemClassLoader,   getSystemResource,   getSystemResourceAsStream,   getSystemResources,   isAncestor,   loadClass,   loadClass,   loadLibrary,   resolveClass,   setClassAssertionStatus,   setDefaultAssertionStatus,   setPackageAssertionStatus,   setSigners
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.tools.ant.AntClassLoader Detail:
 public  void addJavaLibraries() 
    add any libraries that come with different java versions here
 public  void addLoaderPackageRoot(String packageRoot) 
    Adds a package root to the list of packages which must be loaded using this loader. All subpackages are also included.
 public  void addPathComponent(File file) 
    Add a path component. This simply adds the file, unlike addPathElement it does not open jar files and load files from their CLASSPATH entry in the manifest file.
 public  void addPathElement(String pathElement) throws BuildException 
    Adds an element to the classpath to be searched.
 protected  void addPathFile(File pathComponent) throws IOException 
    Add a file to the path. Reads the manifest, if available, and adds any additional class path jars specified in the manifest.
 public  void addSystemPackageRoot(String packageRoot) 
    Adds a package root to the list of packages which must be loaded on the parent loader. All subpackages are also included.
 public  void buildFinished(BuildEvent event) 
    Cleans up any resources held by this classloader at the end of a build.
 public  void buildStarted(BuildEvent event) 
    Empty implementation to satisfy the BuildListener interface.
 public synchronized  void cleanup() 
    Cleans up any resources held by this classloader. Any open archive files are closed.
 protected Class defineClassFromData(File container,
    byte[] classData,
    String classname) throws IOException 
    Define a class given its bytes
 protected  void definePackage(File container,
    String className) throws IOException 
    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
 public Class findClass(String name) throws ClassNotFoundException 
    Searches for and load a class on the classpath of this class loader.
 protected Enumeration findResources(String name) throws IOException 
    Returns an enumeration of URLs representing all the resources with the given name by searching the class loader's classpath.
 protected Enumeration findResources(String name,
    boolean parentHasBeenSearched) throws IOException 
    Returns an enumeration of URLs representing all the resources with the given name by searching the class loader's classpath.
 public Class forceLoadClass(String classname) throws ClassNotFoundException 
    Loads a class through this class loader even if that class is available on the parent classpath. This ensures that any classes which are loaded by the returned class will use this classloader.
 public Class forceLoadSystemClass(String classname) throws ClassNotFoundException 
    Loads a class through this class loader but defer to the parent class loader. This ensures that instances of the returned class will be compatible with instances which have already been loaded on the parent loader.
 public String getClasspath() 
    Returns the classpath this classloader will consult.
 public ClassLoader getConfiguredParent() 
    Gets the parent as has been specified in the constructor or via setParent.
 public Enumeration getNamedResources(String name) throws IOException 
    Finds all the resources with the given name. A resource is some data (images, audio, text, etc) that can be accessed by class code in a way that is independent of the location of the code.

    Would override getResources if that wasn't final in Java 1.4.

 public URL getResource(String name) 
    Finds the resource with the given name. A resource is some data (images, audio, text, etc) that can be accessed by class code in a way that is independent of the location of the code.
 public InputStream getResourceAsStream(String name) 
    Returns a stream to read the requested resource 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.
 public static  void initializeClass(Class theClass) 
Deprecated! since - 1.6.x. Use Class.forName with initialize=true instead.

    Forces initialization of a class in a JDK 1.1 compatible, albeit hacky way.
 protected boolean isInPath(File component) 
    Indicate if the given file is in this loader's path
 protected synchronized Class loadClass(String classname,
    boolean resolve) throws ClassNotFoundException 
    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.
 protected  void log(String message,
    int priority) 
    Logs a message through the project object if one has been provided.
 public  void messageLogged(BuildEvent event) 
    Empty implementation to satisfy the BuildListener interface.
 public static AntClassLoader newAntClassLoader(ClassLoader parent,
    Project project,
    Path path,
    boolean parentFirst) 
    Factory method
 public  void resetThreadContextLoader() 
    Resets the current thread's context loader to its original value.
 public  void setClassPath(Path classpath) 
    Set the classpath to search for classes to load. This should not be changed once the classloader starts to server classes
 public synchronized  void setIsolated(boolean isolated) 
    Sets whether this classloader should run in isolated mode. In isolated mode, classes not found on the given classpath will not be referred to the parent class loader but will cause a ClassNotFoundException.
 public  void setParent(ClassLoader parent) 
    Set the parent for this class loader. This is the class loader to which this class loader will delegate to load classes
 public  void setParentFirst(boolean parentFirst) 
    Control whether class lookup is delegated to the parent loader first or after this loader. Use with extreme caution. Setting this to false violates the class loader hierarchy and can lead to Linkage errors
 public  void setProject(Project project) 
    Set the project associated with this class loader
 public  void setThreadContextLoader() 
    Sets the current thread's context loader to this classloader, storing the current loader value for later resetting.
 public  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.
 public  void subBuildStarted(BuildEvent event) 
    Empty implementation to satisfy the BuildListener interface.
 public  void targetFinished(BuildEvent event) 
    Empty implementation to satisfy the BuildListener interface.
 public  void targetStarted(BuildEvent event) 
    Empty implementation to satisfy the BuildListener interface.
 public  void taskFinished(BuildEvent event) 
    Empty implementation to satisfy the BuildListener interface.
 public  void taskStarted(BuildEvent event) 
    Empty implementation to satisfy the BuildListener interface.
 public String toString() 
    Returns a String representing this loader.