package org.example;
import javax.script.Bindings;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import java.util.logging.Logger;
public class Main {
public static void main(String[] args) throws Exception {
ScriptEngine engine = new ScriptEngineManager().getEngineByName("jshell");
Logger logger = Logger.getLogger("testjshell");
Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
bindings.put("log", logger);
// engine.put("log", logger);
String text = """
System.out.println("HELLO WORLD");
log.info("Hello world.");
""";
engine.eval(text);
}
}
and I get:
Exception in thread "main" javax.script.ScriptException: package ch.obermuhlner.scriptengine.jshell does not exist
Snippet:VariableKey(log)#1-java.util.logging.Logger log = (java.util.logging.Logger) ch.obermuhlner.scriptengine.jshell.VariablesTransfer.getVariableValue("log");
Trying to get a small sample to work with modules.
java source
and I get: