Advertisement
Guest User

Nashorn in Java 15+

a guest
Apr 11th, 2021
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.53 KB | None | 0 0
  1. javax.script.ScriptEngineManager engineManager = new javax.script.ScriptEngineManager();
  2. javax.script.ScriptEngineFactory engineFactory = new org.openjdk.nashorn.api.scripting.NashornScriptEngineFactory();
  3.  
  4. // Register Nashorn library
  5. engineManager.registerEngineName("Nashorn", engineFactory);
  6.  
  7. javax.script.ScriptEngine engine = engineManager.getEngineByName("Nashorn");
  8.  
  9. // Run JavaScript code as usual
  10. try {
  11.     engine.eval("print('Hello World!');");
  12.  
  13. } catch (final javax.script.ScriptException ex) {
  14.     ex.printStackTrace();
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement