You use the jjs
command-line tool to invoke the Nashorn engine.
Synopsis
jjs [options] script-files [-- arguments]
options
This represents one or more options of the jjs
command, separated by spaces. See Options for the jjs Command.
script-files
This represents one or more script files that you want to interpret using the Nashorn engine, separated by spaces. If no files are specified, then an interactive shell is started.
arguments
All values after the double hyphen marker (--
) are passed through to the script or the interactive shell as arguments. These values can be accessed by using the arguments
property.
Description
The jjs
command-line tool is used to invoke the Nashorn engine. You can use it to interpret one or several script files, or to run an interactive shell.
Options for the jjs Command
The options of the jjs
command control the conditions under which scripts are interpreted by Nashorn engine.
-Dname=value
Sets a system property to be passed to the script by assigning a value to a property name. The following example shows how to invoke Nashorn engine in interactive mode and assign myValue
to the property named myKey
:
>> jjs -DmyKey=myValue jjs> java.lang.System.getProperty("myKey") myValue jjs>
This option can be repeated to set multiple properties.
--add-modules modules
Specifies the root user Java modules.
-cp path
or -classpath path
Specifies the path to the supporting class files. To set multiple paths, the option can be repeated, or you can separate each path with the following character:
Oracle Solaris, Linux, and OS X: Colon (:)
Windows; Semicolon (;)
-doe=[true|false]
or -dump-on-error=[true|false]
Provides a full stack trace when an error occurs. By default, only a brief error message is printed. The default parameter is false
.
-fv=[true|false]
or -fullversion=[true|false]
Prints the full Nashorn version string. The default parameter is false
.
-fx=[true|false]
Launches the script as a JavaFX application. The default parameter is false
.
-h
or -help
Prints the list of options and their descriptions.
--language=[es5|es6]
Specifies the ECMAScript language version. The default version is ES5.
--module-path path
Specifies where to find user Java modules.
-ot=[true|false]
or -optimistic-types=[true|false]
Enables or disables optimistic type assumptions with deoptimizing recompilation. This makes the compiler try, for any program symbol whose type can’t be proven at compile time, to type it as narrowly and primitively as possible. If the runtime encounters an error because the symbol type is too narrow, then a wider method is generated until a steady stage is reached. While this produces as optimal Java bytecode as possible, erroneous type guesses will lead to longer warmup. Optimistic typing is currently enabled by default, but it can be disabled for faster startup performance. The default parameter is true
.
-scripting=[true|false]
Enables a shell scripting features. The default parameter is true
.
-strict=[true|false]
Enables a strict mode, which enforces stronger adherence to the standard (ECMAScript Edition 5.1), making it easier to detect common coding errors. The default parameter is false
.
-t=zone
or -timezone=zone
Sets the specified time zone for script execution. It overrides the time zone set in the OS and used by the Date
object. The default zone
is America/Los_Angeles
.
-v=[true|false]
or-version=[true|false]
Prints the Nashorn version string. The default parameter is false
.
Example of Running a Script with Nashorn
jjs script.js
Example of Running Nashorn in Interactive Mode
>> jjs jjs> println("Hello, World!") Hello, World! jjs> quit() >>
Example of Passing Arguments to Nashorn
>> jjs -- a b c jjs> arguments.join(", ") a, b, c jjs>