Clazzy is a basic classloading framework that was made necessary due to a limitation in the JDK's URLClassLoader class, which does not provide a hook to cleanly close underlying jar files (when accessing classes and resources in such files). Under Windows, this forbids deletion of said jar files while the corresponding VM is running - a bugging limitation if you are implementing hot-deployment.


Get the following and you're off:

  • The Loader interface abstracts sources of bytes and "resources". The framework provides such loader implementation that load bytes from the file system or from jar files.
  • The BaseClassLoader provides basic classloading behavior. It supports the JDK's delegation model, and can optionally proceed otherwise if desired (delegating to child classloaders before delegating to the parent classloader).
  • The most useful class in the framework is probably the CompositeClassLoader class. An instance thereof is "composed" of multiple Loaders that are searched sequentially.

Learning by Example

The example below should prove a thorough enough introduction. For more details, see the javadoc and the test cases.

import org.sapia.clazzy.*


  LoaderSelector selector = new DefaultLoaderSelector();
  // the path below can be delimited by ':' or ';'
  String classpath = "/some/path/classes:some/path/lib/some.jar");
  CompositeClassLoader loader = 
                                  new DefaultLoaderSelector(), 
  Class myClass = loader.loadClass("");
  // do not forget the following when you're finished with
  // the classloader: it releases all underlying resources...

Note that if you are using instances in conjunction with this framework, make sure you define the java.protocol.handler.pkgs system property, whose value should be org.sapia. See the javadoc for more details.