@@ -118,7 +118,9 @@ public class JavaEngine extends AbstractScriptEngine {
118
118
private JavaService javaService ;
119
119
120
120
/**
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.
122
124
* <p>
123
125
* The currently active {@link JavaService} is responsible for running the
124
126
* class.
@@ -149,7 +151,9 @@ public Object eval(String script) throws ScriptException {
149
151
}
150
152
151
153
/**
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.
153
157
* <p>
154
158
* The currently active {@link JavaService} is responsible for running the
155
159
* class.
@@ -171,12 +175,16 @@ public Object eval(Reader reader) throws ScriptException {
171
175
}
172
176
173
177
/**
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.
175
182
*
176
183
* @param script the source code for a Java class
177
184
* @return the compiled Java class as {@link Class}.
178
185
*/
179
186
public Class <?> compile (String script ) throws ScriptException {
187
+ // get filename from engine scope bindings
180
188
final String path = (String ) get (FILENAME );
181
189
File file = path == null ? null : new File (path );
182
190
@@ -244,7 +252,10 @@ public Class<?> compile(String script) throws ScriptException {
244
252
}
245
253
246
254
/**
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.
248
259
*
249
260
* @param reader the reader producing the source code for a Java class
250
261
* @return the compiled Java class as {@link Class}.
0 commit comments