Executing Scripts

In this chapter, you will learn:

  • How to use the eval() method of ScriptEngine to execute scripts
  • How to pass parameters from Java code to Nashorn engine
  • How to pass parameters from Nashorn engine to Java

Using the eval() Method

A ScriptEngine can execute a script in a String and a Reader. Using a Reader, you can execute a script stored on the network or in a file. One of the following versions of the eval() method of the ScriptEngine interface is used to execute a script:

  • Object eval(String script)
  • Object eval(Reader reader)
  • Object eval(String script, Bindings bindings)
  • Object eval(Reader reader, Bindings bindings) ...

Get Scripting in Java: Integrating with Groovy and JavaScript now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.