public final class JavaCompiler extends java.lang.Object implements java.lang.Cloneable, TrueStatic
Allows to use external Java compilers (as com.sun.tools.javac)
to compile and load new Java classes and Java formulas
Synchronization note: different threads should use different
instances of this class because the arguments of the compiler are
set through the fields of JavaCompiler instances.
| Modifier and Type | Class and Description |
|---|---|
static class |
JavaCompiler.CannotChangeSourceOfLoadedClassException |
static class |
JavaCompiler.CannotCorrectClassException |
class |
JavaCompiler.CannotFindCompiledClassException |
static interface |
JavaCompiler.CompilationException |
static class |
JavaCompiler.CompilationResults |
class |
JavaCompiler.CompilerErrorException |
static class |
JavaCompiler.EvalReturn |
class |
JavaCompiler.LocalException |
static class |
JavaCompiler.LocalStaticException |
static class |
JavaCompiler.MathFunctionsForFormulaInternal
This class is designed for internal use by
evalXxx methods only. |
class |
JavaCompiler.ToolException |
class |
JavaCompiler.ToolInternalException |
static class |
JavaCompiler.ToolInvalidCallException |
static class |
JavaCompiler.ToolNotFoundException |
static class |
JavaCompiler.UsedTool |
| Modifier and Type | Field and Description |
|---|---|
static int |
DEBUG_LEVEL |
static java.lang.String |
EVAL_DEFAULT_IMPORTS |
static java.lang.String |
EVAL_PACKAGE |
static boolean |
USE_DCO
The system property returned by
call:
it indicates whether this class will use Dynamic Class Overloaders. |
| Modifier and Type | Method and Description |
|---|---|
java.lang.Object |
clone() |
java.lang.Class |
compileAndLoad(java.lang.String source,
java.lang.String mainClassName,
java.lang.ClassLoader parentClassLoader) |
java.lang.Class |
compileAndLoad(java.lang.String source,
java.lang.String mainClassName,
java.lang.ClassLoader parentClassLoader,
net.algart.lib.JavaCompiler.ClassCorrector classCorrector)
Note!
classCorrector and parentClassLoader arguments
are used only when the class is compiled. |
JavaCompiler.CompilationResults |
compileJavaFile(java.io.File javaFile) |
double |
evalDouble(java.lang.String javaExpression) |
double |
evalDouble(java.lang.String javaExpression,
java.lang.Object context) |
double |
evalDouble(java.lang.String javaExpression,
java.lang.Object context,
java.lang.String contextParameterName) |
float |
evalFloat(java.lang.String javaExpression) |
float |
evalFloat(java.lang.String javaExpression,
java.lang.Object context) |
float |
evalFloat(java.lang.String javaExpression,
java.lang.Object context,
java.lang.String contextParameterName) |
int |
evalInt(java.lang.String javaExpression) |
int |
evalInt(java.lang.String javaExpression,
java.lang.Object context) |
int |
evalInt(java.lang.String javaExpression,
java.lang.Object context,
java.lang.String contextParameterName) |
long |
evalLong(java.lang.String javaExpression) |
long |
evalLong(java.lang.String javaExpression,
java.lang.Object context) |
long |
evalLong(java.lang.String javaExpression,
java.lang.Object context,
java.lang.String contextParameterName) |
java.lang.Object |
evalObject(java.lang.String javaExpression) |
java.lang.Object |
evalObject(java.lang.String javaExpression,
java.lang.Object context) |
java.lang.Object |
evalObject(java.lang.String javaExpression,
java.lang.Object context,
java.lang.String contextParameterName) |
java.lang.String |
evalString(java.lang.String javaExpression) |
java.lang.String |
evalString(java.lang.String javaExpression,
java.lang.Object context) |
java.lang.String |
evalString(java.lang.String javaExpression,
java.lang.Object context,
java.lang.String contextParameterName) |
void |
evalVoid(java.lang.String javaExpression) |
void |
evalVoid(java.lang.String javaExpression,
java.lang.Object context) |
void |
evalVoid(java.lang.String javaExpression,
java.lang.Object context,
java.lang.String contextParameterName) |
java.lang.ClassLoader |
getClassLoaderAfterCompileAndLoad(java.lang.ClassLoader parentClassLoader) |
java.lang.String[] |
getCompileAdditionalOptions() |
java.util.Set |
getCompileClassPath() |
java.lang.String |
getCompileDestinationDirectory() |
java.lang.String |
getEvalImports() |
static JavaCompiler |
getInstance() |
static JavaCompiler |
getInstance(JavaCompiler.UsedTool usedTool) |
JavaCompiler.UsedTool |
getUsedTool() |
static void |
invalidateCache()
Enforces
JavaCompiler class to "forget" all classes and class loaders
stored in the internal cache. |
static long |
invalidationCount() |
static void |
main(java.lang.String[] argv) |
void |
setCompileAdditionalOptions(java.lang.String[] value) |
void |
setCompileClassPath(java.util.Set value) |
void |
setCompileDestinationDirectory(java.lang.String value) |
void |
setEvalImports(java.lang.String value) |
public static final int DEBUG_LEVEL
public static final boolean USE_DCO
GlobalProperties.getClassBooleanProperty(JavaCompiler.class, "USE_DCO", true) call:
it indicates whether this class will use Dynamic Class Overloaders.
This property should be set to false only if the TEMP_CLASSES_DIRECTORY property is also set
and included in the standard system CLASSPATH.public static final java.lang.String EVAL_DEFAULT_IMPORTS
public static final java.lang.String EVAL_PACKAGE
public static JavaCompiler getInstance()
public static JavaCompiler getInstance(JavaCompiler.UsedTool usedTool)
public JavaCompiler.UsedTool getUsedTool()
public void setCompileClassPath(java.util.Set value)
public java.util.Set getCompileClassPath()
public void setCompileDestinationDirectory(java.lang.String value)
public java.lang.String getCompileDestinationDirectory()
public void setCompileAdditionalOptions(java.lang.String[] value)
public java.lang.String[] getCompileAdditionalOptions()
public void setEvalImports(java.lang.String value)
public java.lang.String getEvalImports()
public JavaCompiler.CompilationResults compileJavaFile(java.io.File javaFile) throws JavaCompiler.ToolNotFoundException, JavaCompiler.ToolInvalidCallException, JavaCompiler.ToolInternalException, JavaCompiler.CompilerErrorException
public java.lang.Class compileAndLoad(java.lang.String source,
java.lang.String mainClassName,
java.lang.ClassLoader parentClassLoader)
throws java.io.IOException,
JavaCompiler.ToolNotFoundException,
JavaCompiler.ToolInvalidCallException,
JavaCompiler.ToolInternalException,
JavaCompiler.CompilerErrorException,
JavaCompiler.CannotFindCompiledClassException,
JavaCompiler.CannotCorrectClassException
public java.lang.Class compileAndLoad(java.lang.String source,
java.lang.String mainClassName,
java.lang.ClassLoader parentClassLoader,
net.algart.lib.JavaCompiler.ClassCorrector classCorrector)
throws java.io.IOException,
JavaCompiler.ToolNotFoundException,
JavaCompiler.ToolInvalidCallException,
JavaCompiler.ToolInternalException,
JavaCompiler.CompilerErrorException,
JavaCompiler.CannotFindCompiledClassException,
JavaCompiler.CannotCorrectClassException
classCorrector and parentClassLoader arguments
are used only when the class is compiled. It means that they will be be ignored
if you call this method second time (after application start or last
invalidateCache() call) with the same mainClassName
and source.JavaCompiler.CannotChangeSourceOfLoadedClassException - Thrown if this method has been
already called with the same mainClassName but another sourcejava.io.IOExceptionJavaCompiler.ToolNotFoundExceptionJavaCompiler.ToolInvalidCallExceptionJavaCompiler.ToolInternalExceptionJavaCompiler.CompilerErrorExceptionJavaCompiler.CannotFindCompiledClassExceptionJavaCompiler.CannotCorrectClassExceptionpublic java.lang.ClassLoader getClassLoaderAfterCompileAndLoad(java.lang.ClassLoader parentClassLoader)
public void evalVoid(java.lang.String javaExpression)
throws java.lang.Exception
java.lang.Exceptionpublic void evalVoid(java.lang.String javaExpression,
java.lang.Object context)
throws java.lang.Exception
java.lang.Exceptionpublic void evalVoid(java.lang.String javaExpression,
java.lang.Object context,
java.lang.String contextParameterName)
throws java.lang.Exception
java.lang.Exceptionpublic int evalInt(java.lang.String javaExpression)
throws java.lang.Exception
java.lang.Exceptionpublic int evalInt(java.lang.String javaExpression,
java.lang.Object context)
throws java.lang.Exception
java.lang.Exceptionpublic int evalInt(java.lang.String javaExpression,
java.lang.Object context,
java.lang.String contextParameterName)
throws java.lang.Exception
java.lang.Exceptionpublic long evalLong(java.lang.String javaExpression)
throws java.lang.Exception
java.lang.Exceptionpublic long evalLong(java.lang.String javaExpression,
java.lang.Object context)
throws java.lang.Exception
java.lang.Exceptionpublic long evalLong(java.lang.String javaExpression,
java.lang.Object context,
java.lang.String contextParameterName)
throws java.lang.Exception
java.lang.Exceptionpublic float evalFloat(java.lang.String javaExpression)
throws java.lang.Exception
java.lang.Exceptionpublic float evalFloat(java.lang.String javaExpression,
java.lang.Object context)
throws java.lang.Exception
java.lang.Exceptionpublic float evalFloat(java.lang.String javaExpression,
java.lang.Object context,
java.lang.String contextParameterName)
throws java.lang.Exception
java.lang.Exceptionpublic double evalDouble(java.lang.String javaExpression)
throws java.lang.Exception
java.lang.Exceptionpublic double evalDouble(java.lang.String javaExpression,
java.lang.Object context)
throws java.lang.Exception
java.lang.Exceptionpublic double evalDouble(java.lang.String javaExpression,
java.lang.Object context,
java.lang.String contextParameterName)
throws java.lang.Exception
java.lang.Exceptionpublic java.lang.String evalString(java.lang.String javaExpression)
throws java.lang.Exception
java.lang.Exceptionpublic java.lang.String evalString(java.lang.String javaExpression,
java.lang.Object context)
throws java.lang.Exception
java.lang.Exceptionpublic java.lang.String evalString(java.lang.String javaExpression,
java.lang.Object context,
java.lang.String contextParameterName)
throws java.lang.Exception
java.lang.Exceptionpublic java.lang.Object evalObject(java.lang.String javaExpression)
throws java.lang.Exception
java.lang.Exceptionpublic java.lang.Object evalObject(java.lang.String javaExpression,
java.lang.Object context)
throws java.lang.Exception
java.lang.Exceptionpublic java.lang.Object evalObject(java.lang.String javaExpression,
java.lang.Object context,
java.lang.String contextParameterName)
throws java.lang.Exception
java.lang.Exceptionpublic static void invalidateCache()
JavaCompiler class to "forget" all classes and class loaders
stored in the internal cache. May be called when some of your classes
or class loaders that probably were passed as arguments to JavaCompiler
methods, or the loaders of some that classes, become obsolete and can be
released to free memory.
This method must not be called if USE_DCO propetry is false.
This method is never called internally.
java.lang.IllegalStateException - Thrown if USE_DCO contains falsepublic static long invalidationCount()
public java.lang.Object clone()
clone in class java.lang.Objectpublic static void main(java.lang.String[] argv)
throws JavaCompiler.LocalStaticException