public class JavaSourceClassLoader extends AbstractJavaSourceClassLoader
ClassLoader
that loads classes by looking for their source files through a 'source path' and compiling
them on-the-fly.Modifier and Type | Class and Description |
---|---|
private static class |
JavaSourceClassLoader.DiagnosticException |
AbstractJavaSourceClassLoader.ProtectionDomainFactory
Modifier and Type | Field and Description |
---|---|
private javax.tools.JavaCompiler |
compiler |
private java.util.Collection<java.lang.String> |
compilerOptions |
private boolean |
debuggingInfoLines |
private boolean |
debuggingInfoSource |
private boolean |
debuggingInfoVars |
private javax.tools.JavaFileManager |
fileManager |
private java.lang.String |
optionalCharacterEncoding |
private java.io.File[] |
sourcePath |
optionalProtectionDomainFactory
Constructor and Description |
---|
JavaSourceClassLoader() |
JavaSourceClassLoader(java.lang.ClassLoader parentClassLoader) |
Modifier and Type | Method and Description |
---|---|
protected java.lang.Class<?> |
findClass(java.lang.String className)
Implementation of
ClassLoader.findClass(String) . |
(package private) javax.tools.JavaFileManager |
getJavaFileManager()
Creates the underlying
JavaFileManager lazily, because setSourcePath(File[]) and consorts
are called after initialization. |
private static java.lang.String |
getSourceResourceName(java.lang.String className)
Construct the name of a resource that could contain the source code of
the class with the given name.
|
private void |
init() |
void |
setCompilerOptions(java.lang.String[] compilerOptions)
Notice: Don't use the '-g' options - these are controlled through
setDebuggingInfo(boolean, boolean,
boolean) . |
void |
setDebuggingInfo(boolean lines,
boolean vars,
boolean source) |
void |
setSourceFileCharacterEncoding(java.lang.String optionalCharacterEncoding) |
void |
setSourcePath(java.io.File[] sourcePath) |
main, setProtectionDomainFactory
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
private java.io.File[] sourcePath
private java.lang.String optionalCharacterEncoding
private boolean debuggingInfoLines
private boolean debuggingInfoVars
private boolean debuggingInfoSource
private java.util.Collection<java.lang.String> compilerOptions
private javax.tools.JavaCompiler compiler
private javax.tools.JavaFileManager fileManager
public JavaSourceClassLoader()
public JavaSourceClassLoader(java.lang.ClassLoader parentClassLoader)
private void init()
javax.tools.JavaFileManager getJavaFileManager()
JavaFileManager
lazily, because setSourcePath(File[])
and consorts
are called after initialization.public void setSourcePath(java.io.File[] sourcePath)
setSourcePath
in class AbstractJavaSourceClassLoader
sourcePath
- The sequence of directories to search for Java™ source filespublic void setSourceFileCharacterEncoding(java.lang.String optionalCharacterEncoding)
setSourceFileCharacterEncoding
in class AbstractJavaSourceClassLoader
optionalCharacterEncoding
- if null
, use platform default encodingpublic void setDebuggingInfo(boolean lines, boolean vars, boolean source)
setDebuggingInfo
in class AbstractJavaSourceClassLoader
lines
- Whether line number debugging information should be generatedvars
- Whether variables debugging information should be generatedsource
- Whether source file debugging information should be generatedpublic void setCompilerOptions(java.lang.String[] compilerOptions)
setDebuggingInfo(boolean, boolean,
boolean)
.compilerOptions
- All command line options supported by the JDK JAVAC toolprotected java.lang.Class<?> findClass(java.lang.String className) throws java.lang.ClassNotFoundException
ClassLoader.findClass(String)
.findClass
in class java.lang.ClassLoader
java.lang.ClassNotFoundException
private static java.lang.String getSourceResourceName(java.lang.String className)
Notice that member types are declared inside a different type, so the relevant source file is that of the outermost declaring class.
className
- Fully qualified class name, e.g. "pkg1.pkg2.Outer$Inner"