leon.misc
Class LyClassLoader
java.lang.Object
java.lang.ClassLoader
leon.misc.LyClassLoader
public class LyClassLoader
- extends java.lang.ClassLoader
This class defines a specific class loader that enable to load classes located on the computer's
disk but not defined inside the CLASSPATH properties.
How to use: in order to load a specific class, create a LyClassLoader with a classpath
that contains its file definition. Each path of the classpath are separated with the system path
separator (File.pathSeparatorChar
). The classpath can contains directories, ZIP or
JAR archives.
Example :
- Creating a specific classpath: the classes that are defined inside the C:/dev/classes
directory and inside the leo.zip and nardi.jar could be loaded.
-
String myClassPath = "C:/dev/classes;C:/lib/leo.zip;C:/lib/nardi.jar";
- Creating the class loader
-
LyClassLoader loader = new LyClassLoader(myClassPath);
- Loading a class
-
Class classToLoad = loader.loadClass("leon.app.LySession");
Remark: if the class was previously loaded by the primordial class loader, the loadClass
method returns the reference of the existing class that corresponds to the given name. Once a
class is loaded, it is stored and won't be reloaded anymore.
Field Summary |
static java.lang.String |
__VERSION
|
Constructor Summary |
LyClassLoader(java.lang.String classpath)
Class constructor, initialize the classpath with the given value. |
Method Summary |
java.lang.Class<?> |
loadClass(java.lang.String className)
Loads the given class. |
java.lang.Class<?> |
loadClass(java.lang.String className,
boolean resolveIt)
Specific implementation of loadClass : loads the class from the file inside the classpath and
then creates a instance of Class. |
Methods inherited from class java.lang.ClassLoader |
clearAssertionStatus, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
__VERSION
public static final java.lang.String __VERSION
- See Also:
- Constant Field Values
LyClassLoader
public LyClassLoader(java.lang.String classpath)
- Class constructor, initialize the classpath with the given value.
- Parameters:
classpath
- The classpath that defines were classes files are located : this is a
string that defines several path separated with the system path separator
File.pathSeparatorChar
.
loadClass
public java.lang.Class<?> loadClass(java.lang.String className)
throws java.lang.ClassNotFoundException
- Loads the given class. Invoking this method is equivalent to invoking
loadClass(name, true)
.
- Overrides:
loadClass
in class java.lang.ClassLoader
- Parameters:
className
- The fully qualified name of the desired class.
- Returns:
- The loaded Class.
- Throws:
java.lang.ClassNotFoundException
- if the class is not found- See Also:
loadClass(String, boolean)
loadClass
public java.lang.Class<?> loadClass(java.lang.String className,
boolean resolveIt)
throws java.lang.ClassNotFoundException
- Specific implementation of loadClass : loads the class from the file inside the classpath and
then creates a instance of Class. If the class has been already loaded by the primordial
class loader, then this reference is returned. *
- Overrides:
loadClass
in class java.lang.ClassLoader
- Parameters:
className
- the complete class name with the package definition (ex:
leon.misc.LyClassLoader)resolveIt
- indicates if the class has to be resolved or not.
- Returns:
- the found Class object.
- Throws:
java.lang.ClassNotFoundException
- if the class is not found
java.lang.ClassFormatError
- if the retrieved class does not matches the class format.
Website: W4 S.A., contact us: support@w4global.com