Enum CompilerUtils
- All Implemented Interfaces:
Serializable, Comparable<CompilerUtils>
This class support loading and debugging Java Classes dynamically.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanaddClassPath(@NotNull String dir) Add a directory to the class path for compiling.static voiddefineClass(@NotNull String className, @NotNull byte[] bytes) Define a class for byte code.static ClassdefineClass(@Nullable ClassLoader classLoader, @NotNull String className, @NotNull byte[] bytes) Define a class for byte code.static ClassloadFromResource(@NotNull String className, @NotNull String resourceName) Load a java class file from the classpath or local file system.static CompilerUtilsReturns the enum constant of this type with the specified name.static CompilerUtils[]values()Returns an array containing the constants of this enum type, in the order they are declared.static booleanwriteBytes(@NotNull File file, @NotNull byte[] bytes) static boolean
-
Field Details
-
DEBUGGING
public static final boolean DEBUGGING -
CACHED_COMPILER
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum type has no constant with the specified nameNullPointerException- if the argument is null
-
loadFromResource
public static Class loadFromResource(@NotNull @NotNull String className, @NotNull @NotNull String resourceName) throws IOException, ClassNotFoundException Load a java class file from the classpath or local file system.- Parameters:
className- expected class name of the outer class.resourceName- as the full file name with extension.- Returns:
- the outer class loaded.
- Throws:
IOException- the resource could not be loaded.ClassNotFoundException- the class name didn't match or failed to initialise.
-
addClassPath
Add a directory to the class path for compiling. This can be required with custom- Parameters:
dir- to add.- Returns:
- whether the directory was found, if not it is not added either.
-
defineClass
Define a class for byte code.- Parameters:
className- expected to load.bytes- of the byte code.
-
defineClass
public static Class defineClass(@Nullable @Nullable ClassLoader classLoader, @NotNull @NotNull String className, @NotNull @NotNull byte[] bytes) Define a class for byte code.- Parameters:
classLoader- to load the class into.className- expected to load.bytes- of the byte code.
-
writeText
-
writeBytes
-