Class Loading


About:

This section describes the order in which the class loader searches for classes on the file system and how additional classes are automatically loaded. This section is also relevant to any command in the java package that makes a reference to a java class (i.e. java::new). References to unresolved classes will implicitly use the TclClassLoader to find unresolved classes.

The process of resolving a class is done by searching for the class in the following locations.

  1. Search the cache of previously loaded classes.

  2. Search for the class using the context class loader. Typically, this means searching on the CLASSPATH via the system class loader.

  3. Search the pathList list, looking only in directories or jar files specified by pathList. (Available only for the java::load command)

  4. Search pathList again, inspecting all jar files found in each directory. (Available only for the java::load command)

  5. Search the env(TCL_CLASSPATH) list, looking only in directories or jar files specified by env(TCL_CLASSPATH).

  6. Search env(TCL_CLASSPATH) again, inspecting all jar files found in each directory.

Note
env(CLASSPATH) is a string of directories or jar files, separated by ":" (unix) or ";" (windows).
env(TCL_CLASSPATH) is a list of directories or jar files.

If the context class loader fails to load the class (step [2]), this typically means that the class could not be located on the CLASSPATH. The CLASSPATH is normally set before the JVM is launched, and is not changed after that. If the user needs to add a class search path at runtime, the env(TCL_CLASSPATH) environment variable should be used. A security check is done to assure that the class does not have access to package-protected variables. If the extension name begins with "java." or "tcl.", a Tcl error is generated.

If a path in pathList or env(TCL_CLASSPATH) is not an absolute path, it is assumed to be a relative path from the interpreter's current directory.

Steps [3] and [5] only use the paths in pathList or env(TCL_CLASSPATH) to locate the class file. If the path is a directory, the loader looks in that directory for the class file. If the path is a jar file, the jar file is inspected to see if it contains the class. Steps [4] and [6] search pathList and env(TCL_CLASSPATH) again. If a path in the list is a directory, the loader looks for jar files in that directory, inspecting any jar files found to locate the class. The loader is capable of extracting files from a compressed jar file.

Any class referenced by extensionName will also be loaded into the VM. This includes classes used in new expressions as well as those whose instances are reported (i.e. the use of static methods.) Due to the recursive nature of class loading, any class referenced must be located on the CLASSPATH, env(TCL_CLASSPATH) or pathList. If a class cannot be located in one of the three locations, a Tcl error is generated.

Currently it is not possible to unload or reload an extension.

Copyright © 1997-1998 Sun Microsystems, Inc.