Last update: 2011-06-23

org.proteios.util
Class JarClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by org.proteios.util.JarClassLoader

public final class JarClassLoader
extends ClassLoader

A class loader implementation that loads classes from JAR files. Each JAR file requires a separate instance of this class. Use the getInstance(String) method to get an existing or create a new instance for a specific JAR file. If the classes in the JAR file requires other classes in another JAR file to work, the paths to those JAR files must be listed in the Class-Path attribute in the META-INF/MANIFEST.MF file. For example:

  Manifest-Version: 1.0
  Class-Path: OtherJarPlugin.jar
 
If more than one JAR is needed separate them with one or more spaces. Note! It is only the Class-Path entry for the JAR file passed to the getInstance(String) method that is checked. The manifest file is not checked for the other JARs.

Version:
2.0
Author:
Nicklas
Last modified
$Date: 2009-04-09 08:48:11 +0200 (Thu, 09 Apr 2009) $

Method Summary
static boolean exists(String jarPath)
          Check if a class loader for the given JAR file exists.
protected  Class<?> findClass(String name)
           
protected  URL findResource(String name)
           
static ClassLoader getInstance(String jarPath)
          Get a class loader for the specified JAR file.
static void unload(String jarPath)
          Unload the class loader for the given JAR file.
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findResources, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static final ClassLoader getInstance(String jarPath)
                                     throws IOException
Get a class loader for the specified JAR file. If a class loader for the specified file already exists, that class loader is returned, otherwise a new class loader is created.

Parameters:
jarPath - The path to a JAR file
Returns:
A class loader
Throws:
IOException - If the jar file can't be loaded

unload

public static final void unload(String jarPath)
Unload the class loader for the given JAR file. The class loader will not be unloaded if the calling application has object references to the class loader or any class loaded by the class loader. However, if the getInstance(String) method is called again, a new class loader instance will be created.

Parameters:
jarPath - The path to the JAR file

exists

public static final boolean exists(String jarPath)
Check if a class loader for the given JAR file exists.

Parameters:
jarPath - The path to the JAR file
Returns:
TRUE if a class loader exists, FALSE otherwise

findClass

protected Class<?> findClass(String name)
                      throws ClassNotFoundException
Overrides:
findClass in class ClassLoader
Throws:
ClassNotFoundException

findResource

protected URL findResource(String name)
Overrides:
findResource in class ClassLoader

Last update: 2011-06-23