@@ -118,7 +118,9 @@ public class JavaEngine extends AbstractScriptEngine {
118118 private JavaService javaService ;
119119
120120 /**
121- * Compiles and runs the specified {@code .java} class.
121+ * Compiles and runs the specified {@code .java} class. If a filename is set
122+ * in the engine scope bindings via the {@link ScriptEngine#FILENAME} key,
123+ * this method compiles that file and runs the resulting main class instead.
122124 * <p>
123125 * The currently active {@link JavaService} is responsible for running the
124126 * class.
@@ -149,7 +151,9 @@ public Object eval(String script) throws ScriptException {
149151 }
150152
151153 /**
152- * Compiles and runs the specified {@code .java} class.
154+ * Compiles and runs the specified {@code .java} class. If a filename is set
155+ * in the engine scope bindings via the {@link ScriptEngine#FILENAME} key,
156+ * this method compiles that file and runs the resulting main class instead.
153157 * <p>
154158 * The currently active {@link JavaService} is responsible for running the
155159 * class.
@@ -171,12 +175,16 @@ public Object eval(Reader reader) throws ScriptException {
171175 }
172176
173177 /**
174- * Compiles and runs the specified {@code .java} class.
178+ * Compiles and runs the specified {@code .java} class. If a filename is set
179+ * in the engine scope bindings via the {@link ScriptEngine#FILENAME} key,
180+ * this method compiles that file and returns its resulting main class
181+ * instead.
175182 *
176183 * @param script the source code for a Java class
177184 * @return the compiled Java class as {@link Class}.
178185 */
179186 public Class <?> compile (String script ) throws ScriptException {
187+ // get filename from engine scope bindings
180188 final String path = (String ) get (FILENAME );
181189 File file = path == null ? null : new File (path );
182190
@@ -244,7 +252,10 @@ public Class<?> compile(String script) throws ScriptException {
244252 }
245253
246254 /**
247- * Compiles and runs the specified {@code .java} class.
255+ * Compiles and runs the specified {@code .java} class. If a filename is set
256+ * in the engine scope bindings via the {@link ScriptEngine#FILENAME} key,
257+ * this method compiles that file and returns its resulting main class
258+ * instead.
248259 *
249260 * @param reader the reader producing the source code for a Java class
250261 * @return the compiled Java class as {@link Class}.
0 commit comments