Java Reference
In-Depth Information
CHAPTER 18
Nashorn and Scripting
In Java 6, the javax.script package was included. It enabled developers to embed
code written in scripting languages into Java applications. This began a new generation
of applications, as developers were able to construct Java solutions containing scripts
written in languages such as JavaScript and Python. The JavaScript engine that was used
in Java 6 was called Rhino. It is an implementation of the JavaScript engine, developed
entirely in Java. While it contains a full JavaScript implementation, it is an older engine
and is no longer compliant with current JavaScript Standards.
Java 8 introduced a new JavaScript engine called Nashorn. It is based on the
ECMAScript-262 Edition 5.1 language specification and supports the javax.script
API introduced in Java 6. Besides bringing a modern JavaScript engine to the Java plat-
form, Nashorn also contains a few new features that make developing JavaScript and
Java solutions easier and more robust. The new command-line tool called jjs provides
scripting abilities above and beyond those that were available with jrunscript .
Nashorn also has full access to the JavaFX 8 API, allowing developers to construct
JavaFX applications completely in JavaScript.
This chapter touches on using the Nashorn engine to construct solutions that integ-
rate the worlds of Java and JavaScript. It does not cover all of the features available with
Nashorn, but you with provides enough to get up and running with this powerful new
Java 8 feature.
18-1. Loading and Executing JavaScript
from Java
Problem
Search WWH ::




Custom Search