org.grinvin.util
Class LocalClassLoader
ClassLoader
org.grinvin.util.LocalClassLoader
public class LocalClassLoader
extends ClassLoader
Class loader which loads classes from a
local classpath, i.e., a
set of directories on the local file system.
To load a class two different methods can be used:
- Using
LocalClassLoader
which is the standard method to retrieve a
class with a given name. - Using
loadClassFromFile(File)
to retrieve a class from a given
class file.
void | addDirectory(File dir) - Add a directory to the local class path.
|
void | addDirectory(File file, String name) - Add a base directory which is derived from the given class name
which is known to reside in the given file.
|
protected Class> | findClass(String name)
|
protected URL | findResource(String name)
|
Iterable | getLocalClasspath() - Return the local class path, i.e., the directories
which are currently used to load classes from.
|
Class> | loadClassFromFile(File file) - Load a class from a given class file.
|
LocalClassLoader
public LocalClassLoader()
Creates a new instance of LocalClassLoader
addDirectory
public void addDirectory(File dir)
Add a directory to the local class path. No action is taken
when the directory already belongs to the local class path.
addDirectory
public void addDirectory(File file,
String name)
Add a base directory which is derived from the given class name
which is known to reside in the given file.
findClass
protected Class> findClass(String name)
throws ClassNotFoundException
findResource
protected URL findResource(String name)
getLocalClasspath
public Iterable getLocalClasspath()
Return the local class path, i.e., the directories
which are currently used to load classes from.
Note that this method returns an iterable and not a list. This return
value is intended to be used in a for each loop:
for (File dir : myClassLoader().getLocalClasspath()) {
// do something with dir
}
loadClassFromFile
public Class> loadClassFromFile(File file)
throws ClassNotFoundException
Load a class from a given class file. Apart from loading the file,
the system also tries to guess what is the directory for the base
package of this file and adds it to the local class path. This should
enable resolution of other local classes referred to by this class.