public class JavaEngine extends AbstractScriptEngine
ScriptEngine compiling and executing Java classes.
Thanks to MiniMaven, this script engine can handle individual Java classes as well as trivial Maven projects (triggered when the proviede script path suggests that the file is part of a Maven project).
engineScopeBindings, scriptContextARGV, ENGINE, ENGINE_VERSION, FILENAME, LANGUAGE, LANGUAGE_VERSION, NAME| Constructor and Description |
|---|
JavaEngine() |
| Modifier and Type | Method and Description |
|---|---|
void |
compile(File file)
Compiles the specified
.java file. |
void |
compile(File file,
Writer errorWriter)
Compiles the specified
.java file. |
Class<?> |
compile(Reader reader)
Compiles and runs the specified
.java class. |
Class<?> |
compile(String script)
Compiles and runs the specified
.java class. |
Object |
eval(Reader reader)
Compiles and runs the specified
.java class. |
Object |
eval(String script)
Compiles and runs the specified
.java class. |
void |
makeJar(File file,
boolean includeSources,
File output,
Writer errorWriter)
Packages the build product into a
.jar file. |
createBindings, eval, eval, eval, eval, get, getBindings, getContext, getFactory, log, put, setBindings, setContext, setLogServicepublic Object eval(String script) throws ScriptException
.java class. If a filename is set
in the engine scope bindings via the ScriptEngine.FILENAME key,
this method compiles that file and runs the resulting main class instead.
The currently active RunService is responsible for running the
class.
eval in interface ScriptEngineeval in class AbstractScriptEnginescript - the source code for a Java classScriptExceptionpublic Object eval(Reader reader) throws ScriptException
.java class. If a filename is set
in the engine scope bindings via the ScriptEngine.FILENAME key,
this method compiles that file and runs the resulting main class instead.
The currently active RunService is responsible for running the
class.
eval in interface ScriptEngineeval in class AbstractScriptEnginereader - the reader producing the source code for a Java classScriptExceptionpublic Class<?> compile(String script) throws ScriptException
.java class. If a filename is set
in the engine scope bindings via the ScriptEngine.FILENAME key,
this method compiles that file and returns its resulting main class
instead.script - the source code for a Java classClass.ScriptExceptionpublic Class<?> compile(Reader reader) throws ScriptException
.java class. If a filename is set
in the engine scope bindings via the ScriptEngine.FILENAME key,
this method compiles that file and returns its resulting main class
instead.reader - the reader producing the source code for a Java classClass.ScriptExceptionpublic void compile(File file)
.java file. Errors are written to the
context error writer.file - the source codecompile(File, Writer),
compile(Reader),
compile(String)public void compile(File file, Writer errorWriter)
.java file. Errors are written to the
specified errorWriter or if it is null, to the context error writer.file - the source codeerrorWriter - where to write the errors or null to use context
errorWritercompile(File),
compile(Reader),
compile(String)public void makeJar(File file, boolean includeSources, File output, Writer errorWriter)
.jar file.file - a .java or pom.xml fileincludeSources - whether to include the sources or notoutput - the .jar file to write toerrorWriter - the destination for error messagesCopyright © 2015–2022 SciJava. All rights reserved.