Class AbstractJavaSourceClassLoader
java.lang.Object
java.lang.ClassLoader
org.codehaus.commons.compiler.AbstractJavaSourceClassLoader
- Direct Known Subclasses:
JavaSourceClassLoader, JavaSourceClassLoader
A
ClassLoader that, unlike usual ClassLoaders, does not load byte code, but reads Java source
code and then scans, parses, compiles and loads it into the virtual machine.
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 AbstractJavaSourceClassLoader and create a new one.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetResourceAsStream(String name) static voidReads Java 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 arguments.abstract voidsetDebuggingInfo(boolean lines, boolean vars, boolean source) final voidsetProtectionDomainFactory(AbstractJavaSourceClassLoader.ProtectionDomainFactory protectionDomainFactory) final voidsetSandboxPolicy(SandboxPolicy policy) Restricts the APIs that the loaded classes may use.abstract voidsetSourceCharset(Charset charset) voidsetSourceFileCharacterEncoding(String charsetName) abstract voidsetSourceFinder(ResourceFinder sourceFinder) abstract voidsetSourcePath(File[] sourcePath) voidsetTargetVersion(int version) Generates class files that target a specified release of the virtual machine, in analogy with JAVAC's-targetcommand line option.Methods inherited from class ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
Field Details
-
protectionDomainFactory
- See Also:
-
sandboxPolicy
- See Also:
-
-
Constructor Details
-
AbstractJavaSourceClassLoader
public AbstractJavaSourceClassLoader() -
AbstractJavaSourceClassLoader
-
-
Method Details
-
getResourceAsStream
- Overrides:
getResourceAsStreamin classClassLoader
-
setSourcePath
- Parameters:
sourcePath- The sequence of directories to search for Java source files
-
setSourceFinder
- Parameters:
sourceFinder- Is used when searching for Java source files
-
setSourceFileCharacterEncoding
-
setSourceCharset
- Parameters:
charset- The character set to using when reading characters from a source file
-
setDebuggingInfo
public abstract void setDebuggingInfo(boolean lines, boolean vars, boolean source) - 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
-
setTargetVersion
public void setTargetVersion(int version) Generates class files that target a specified release of the virtual machine, in analogy with JAVAC's-targetcommand line option. May be ignored by an implementation. Allowed values, and the default value, depend on the implementation.-1means to use a default version.- See Also:
-
setSandboxPolicy
Restricts the APIs that the loaded classes may use. If set, then each generated class is verified against the policy before it is defined, and loading fails with aClassNotFoundException(whose cause is aSandboxViolationException) if the class uses any field, method or constructor that the policy does not allow.Must be called before the first class is loaded.
null(the default) means that the loaded classes are not restricted.If a policy is set, then the generated classes always contain debugging information about the source file and the line numbers, so that the violations can be reported with their source locations (see
SandboxViolation.getLocation()).- See Also:
-
setProtectionDomainFactory
public final void setProtectionDomainFactory(@Nullable AbstractJavaSourceClassLoader.ProtectionDomainFactory protectionDomainFactory) - See Also:
-
main
Reads Java 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 arguments.Usage is as follows:
java
AbstractJavaSourceClassLoader[ option ] ... class-name [ argument ] ... option: -sourcepath colon-separated-list-of-source-directories -encoding character-encoding -g Generate all debugging info -g:none Generate no debugging info -g:{source,lines,vars} Generate only some debugging info- Throws:
Exception
-