Class JavaSourceClassLoader
java.lang.Object
java.lang.ClassLoader
org.codehaus.commons.compiler.AbstractJavaSourceClassLoader
org.codehaus.commons.compiler.jdk.JavaSourceClassLoader
A
ClassLoader that loads classes by looking for their source files through a "source path" and compiling
them on-the-fly.
Notice that this class loader does not support resoures in the sense of ClassLoader.getResource(String),
ClassLoader.getResourceAsStream(String) nd ClassLoader.getResources(String).
- See Also:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class AbstractJavaSourceClassLoader
AbstractJavaSourceClassLoader.ProtectionDomainFactory -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Collection<String> private booleanprivate booleanprivate booleanprivate JavaFileManagerprivate Charsetprivate ResourceFinderprivate static final JavaCompilerFields inherited from class AbstractJavaSourceClassLoader
protectionDomainFactory -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Class<?> Implementation ofClassLoader.findClass(String).private Class<?> findClass2(String className) private JavaFileObjectfindClassFile(String className) private JavaFileManagerCreates the underlyingJavaFileManagerlazily, becausesetSourcePath(File[])and consorts are called after initialization.private static StringgetSourceResourceName(String className) Constructs the name of a resource that could contain the source code of the class with the given name.private static JavaCompilerprivate voidinit()voidsetCompilerOptions(String[] compilerOptions) Notice: Don't use the '-g' options - these are controlled throughsetDebuggingInfo(boolean, boolean, boolean).voidsetDebuggingInfo(boolean lines, boolean vars, boolean source) voidsetSourceCharset(Charset charset) voidsetSourceFinder(ResourceFinder sourceFinder) voidsetSourcePath(File[] sourcePath) Methods inherited from class AbstractJavaSourceClassLoader
getResourceAsStream, main, setProtectionDomainFactory, setSourceFileCharacterEncodingMethods inherited from class ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResource, findResources, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
Field Details
-
SYSTEM_JAVA_COMPILER
-
sourceFinder
-
sourceCharset
-
debuggingInfoLines
private boolean debuggingInfoLines -
debuggingInfoVars
private boolean debuggingInfoVars -
debuggingInfoSource
private boolean debuggingInfoSource -
compilerOptions
-
fileManager
-
-
Constructor Details
-
JavaSourceClassLoader
public JavaSourceClassLoader()- See Also:
-
JavaSourceClassLoader
- See Also:
-
-
Method Details
-
getSystemJavaCompiler
-
init
private void init() -
getJavaFileManager
Creates the underlyingJavaFileManagerlazily, becausesetSourcePath(File[])and consorts are called after initialization. -
setSourcePath
- Specified by:
setSourcePathin classAbstractJavaSourceClassLoader- Parameters:
sourcePath- The sequence of directories to search for Java source files
-
setSourceFinder
- Specified by:
setSourceFinderin classAbstractJavaSourceClassLoader- Parameters:
sourceFinder- Is used when searching for Java source files
-
setSourceCharset
- Specified by:
setSourceCharsetin classAbstractJavaSourceClassLoader- Parameters:
charset- The character set to using when reading characters from a source file
-
setDebuggingInfo
public void setDebuggingInfo(boolean lines, boolean vars, boolean source) - Specified by:
setDebuggingInfoin classAbstractJavaSourceClassLoader- Parameters:
lines- Whether line number debugging information should be generatedvars- Whether variables debugging information should be generatedsource- Whether source file debugging information should be generated
-
setCompilerOptions
Notice: Don't use the '-g' options - these are controlled throughsetDebuggingInfo(boolean, boolean, boolean).- Parameters:
compilerOptions- All command line options supported by the JDK JAVAC tool
-
findClass
Implementation ofClassLoader.findClass(String).- Overrides:
findClassin classClassLoader- Throws:
ClassNotFoundException
-
findClass2
- Throws:
IOException
-
findClassFile
- Throws:
IOException
-
getSourceResourceName
Constructs the name of a resource that could contain the source code of the class with the given name.Notice that member types are declared inside a different type, so the relevant source file is that of the outermost declaring class.
- Parameters:
className- Fully qualified class name, e.g. "pkg1.pkg2.Outer$Inner"- Returns:
- the name of the resource, e.g. "pkg1/pkg2/Outer.java"
-