public class CachedCompiler extends Object implements Closeable
close() once finished and use
updateFileManagerForClassLoader(ClassLoader, java.util.function.Consumer)
to tune a specific loader.| Modifier and Type | Field and Description |
|---|---|
Function<StandardJavaFileManager,MyJavaFileManager> |
fileManagerOverride
Optional testing hook to replace the file manager implementation.
|
| Constructor and Description |
|---|
CachedCompiler(@Nullable File sourceDir,
@Nullable File classDir)
Create a compiler that optionally writes sources and classes to the given
directories.
|
CachedCompiler(@Nullable File sourceDir,
@Nullable File classDir,
@NotNull List<String> options)
Create a compiler with explicit compiler options.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Close any file managers created by this compiler.
|
Class<?> |
loadFromJava(@NotNull ClassLoader classLoader,
@NotNull String className,
@NotNull String javaCode)
Compile the source using the supplied class loader.
|
Class<?> |
loadFromJava(@NotNull ClassLoader classLoader,
@NotNull String className,
@NotNull String javaCode,
@Nullable PrintWriter writer)
Compile and load using a specific class loader and writer.
|
Class<?> |
loadFromJava(@NotNull String className,
@NotNull String javaCode)
Compile the supplied source and load the class using this instance's
class loader.
|
void |
updateFileManagerForClassLoader(ClassLoader classLoader,
Consumer<MyJavaFileManager> updateFileManager)
Update the file manager for a specific class loader.
|
public Function<StandardJavaFileManager,MyJavaFileManager> fileManagerOverride
public CachedCompiler(@Nullable
@Nullable File sourceDir,
@Nullable
@Nullable File classDir)
sourceDir or classDir is not null, the
corresponding files are written for debugging purposes.public CachedCompiler(@Nullable
@Nullable File sourceDir,
@Nullable
@Nullable File classDir,
@NotNull
@NotNull List<String> options)
CachedCompiler(File, File) and allow inspection of generated
output.sourceDir - where sources are dumped when not nullclassDir - where class files are dumped when not nulloptions - additional flags passed to the Java compilerpublic void close()
close in interface Closeableclose in interface AutoCloseablepublic Class<?> loadFromJava(@NotNull @NotNull String className, @NotNull @NotNull String javaCode) throws ClassNotFoundException
className - expected binary name of the classjavaCode - source code to compileClassNotFoundException - if the compiled class cannot be definedpublic Class<?> loadFromJava(@NotNull @NotNull ClassLoader classLoader, @NotNull @NotNull String className, @NotNull @NotNull String javaCode) throws ClassNotFoundException
classLoader - loader to define the class withclassName - expected binary namejavaCode - source code to compileClassNotFoundException - if definition failspublic Class<?> loadFromJava(@NotNull @NotNull ClassLoader classLoader, @NotNull @NotNull String className, @NotNull @NotNull String javaCode, @Nullable @Nullable PrintWriter writer) throws ClassNotFoundException
classLoader - loader to define the class withclassName - expected binary namejavaCode - source code to compilewriter - destination for diagnostic messages, may be nullClassNotFoundException - if definition failspublic void updateFileManagerForClassLoader(ClassLoader classLoader, Consumer<MyJavaFileManager> updateFileManager)
classLoader - the class loader to updateupdateFileManager - function applying the updateCopyright © 2025. All rights reserved.