The jrunscript shell also creates aliases for several Java classes such as
java.io.File , j ava.io.Reader , j ava.net.URL , and so on, so you can refer to them
by their simple names. Several other objects are also exposed as global objects by
jrunscript . You can get the entire list of global objects and their types printed on the
command-line using the following command. Only partial output has been shown.
Notice that the output will also include a property named p , which is the variable name
declared in the for loop.
nashorn> for(var p in this) print(p, typeof this[p]);
The JDK includes a script-engine-independent command-line shell called jrunscript .
It can be used to evaluate scripts entered on the command-line or from files. You can find
this shell in the JAVA_HOME\bin directory, where JAVA_HOME is the directory in which you
have installed the JDK.
The jrunscript command-line shell can run scripts written in any scripting
language supported by Java. By default, it runs Nashorn scripts. To use a scripting
language other than Nashorn, you need to include the language's JAR file with
jrunscript using the -cp or -classpath option. The -l option lets you choose the
scripting language you want to use.
You can use jrunscript in one-liner mode, batch mode, and interactive mode.
The one-liner mode lets you execute one line of script. You invoke the one-liner mode
using the -e option. The batch mode lets you execute scripts stored in a file. You invoke
the batch mode using the -f option. The interactive mode lets you execute scripts entered
on the command-line interactively. You invoke interactive mode by not using the -e and
-f options, or by using the -f - option (note a following - after -f ).
You can list all of the available script engines with jrunscript using the -q option.
Notice that you must include the script engine's JAR files for languages other than
Nashorn to make them available with jrunscript . Several useful global functions and
objects are made available by the jrunscript shell. For example, the cat() function can
be used to print the contents of a file or URL, optionally applying a filter.