org.codehaus.janino
public class JavaSourceClassLoader extends ClassLoader
As with any ClassLoader, it is not possible to "update" classes after they've been loaded. The way to achieve this is to give up on the JavaSourceClassLoader and create a new one.
Nested Class Summary | |
---|---|
interface | JavaSourceClassLoader.ProtectionDomainFactory |
Constructor Summary | |
---|---|
JavaSourceClassLoader(ClassLoader parentClassLoader, File[] optionalSourcePath, String optionalCharacterEncoding, EnumeratorSet debuggingInformation)
Set up a JavaSourceClassLoader that finds JavaTM source code in a file
that resides in either of the directories specified by the given source path.
| |
JavaSourceClassLoader(ClassLoader parentClassLoader, ResourceFinder sourceFinder, String optionalCharacterEncoding, EnumeratorSet debuggingInformation)
Set up a JavaSourceClassLoader that finds JavaTM source code through
a given ResourceFinder.
|
Method Summary | |
---|---|
protected Class | defineBytecode(String className, byte[] ba)
Calls java.lang.ClassLoader#defineClass(java.lang.String, byte[], int, int)
or java.lang.ClassLoader#defineClass(java.lang.String, byte[], int, int, java.security.ProtectionDomain) ,
depending on whether or not a ProtectionDomainFactory was set.
|
protected Class | defineBytecodes(String name, Map bytecodes)
Define a set of classes, like
java.lang.ClassLoader#defineClass(java.lang.String, byte[], int, int) .
|
protected Class | findClass(String name)
Implementation of ClassLoader#findClass(String).
|
protected Map | generateBytecodes(String name)
Find, scan, parse the right compilation unit. |
static void | main(String[] args)
Read JavaTM source code for a given class name, scan, parse, compile and load
it into the virtual machine, and invoke its "main()" method with the given args.
|
void | setCompileErrorHandler(UnitCompiler.ErrorHandler optionalCompileErrorHandler) |
void | setProtectionDomainFactory(JavaSourceClassLoader.ProtectionDomainFactory protectionDomainFactory) |
void | setWarningHandler(WarningHandler optionalWarningHandler) |
You can specify to include certain debugging information in the generated class files, which is useful if you want to debug through the generated classes (see Scanner).
Parameters: parentClassLoader See ClassLoader optionalSourcePath A collection of directories that are searched for JavaTM source files in the given order optionalCharacterEncoding The encoding of the JavaTM source files (null
for platform default encoding) debuggingInformation What kind of debugging information to generate, see DebuggingInformation
You can specify to include certain debugging information in the generated class files, which is useful if you want to debug through the generated classes (see Scanner).
Parameters: parentClassLoader See ClassLoader sourceFinder Used to locate additional source files optionalCharacterEncoding The encoding of the JavaTM source files (null
for platform default encoding) debuggingInformation What kind of debugging information to generate, see DebuggingInformation
java.lang.ClassLoader#defineClass(java.lang.String, byte[], int, int)
or java.lang.ClassLoader#defineClass(java.lang.String, byte[], int, int, java.security.ProtectionDomain)
,
depending on whether or not a ProtectionDomainFactory was set.
See Also: JavaSourceClassLoader
java.lang.ClassLoader#defineClass(java.lang.String, byte[], int, int)
.
If the bytecodes
contains an entry for name
, then the
Class defined for that name is returned.
Parameters: bytecodes String name => byte[] bytecode
Throws: ClassNotFoundException
Returns: String name => byte[] bytecode, or null
if no source code could be found
Throws: ClassNotFoundException on compilation problems
Usage is as follows:
java [ java-option ] org.codehaus.janino.JavaSourceClassLoader [ option ] ... class-name [ arg ] ... java-option Any valid option for the Java Virtual Machine (e.g. "-classpath colon-separated-list-of-class-directories") option: -sourcepath colon-separated-list-of-source-directories -encoding character-encoding -g Generate all debugging info"); -g:none Generate no debugging info"); -g:{lines,vars,source} Generate only some debugging info"); -cache dir Cache compiled classes here");
See Also: UnitCompiler
See Also: setWarningHandler UnitCompiler