| This Chapter | |
| - | Chapter 3: Scripting |
| - | Core Types |
| - | Listing All Script Engines |
| - | Running Scripts |
| - | Binding Scripts |
| - | Using Invocable |
| - | Using Compilable |
| - | Summary |
JSR 223, Scripting for the Java Platform describes various mechanisms for allowing scripting language programs to access information in the Java platform and permitting scripting language pages to be used in a Java server-side application. The concept of enabling communication between scripts and program objects itself is not new. A notable example is how JavaScript, the scripting language supported by most browsers, can access methods in Java applets or Flash programs. A non-Java example: VBScript that can be used to access ActiveX objects inside Microsoft Office applications.
Note
The JSR 223 documentation can be downloaded from http://jcp.org/en/jsr/detail?id=223
JSR 223 defines a standard on how to do this kind of communication with multiple script languages. Java 6 provides a script engine based on Rhino, an open source implementation of JavaScript. Rhino is written in Java and can be downloaded from http://www.mozilla.org/rhino. Support for other scripting languages can be found in the Scripting project at java.net (https://scripting.dev.java.net). The languages supported so far in this project include Groovy, Java, Jelly, Jexl, JudoScript, OGNL, Pnuts, Python, Ruby, Scheme, Sleep, Tcl, xpath, and XSLT. This chapter concentrates on the JavaScript engine in Java 6.
The Scripting API is defined and implemented as types in the javax.script package. This package offers the following areas of functionality.
The rest of this section takes a look at the core types in the javax.script package and provide several examples.