Java Reference
In-Depth Information
$ jjs - DmyKey = myValue
jjs > java . lang . System . getProperty ( "myKey" );
myValue
-v or -version is the standard Nashorn version string.
-fv or -fullversion prints the full Nashorn version string.
-fx is used to execute a script as a JavaFX GUI application. This allows a Jav‐
aFX programmer to write a lot less boilerplate by making use of Nashorn. 1
-h is the standard help switch.
-scripting can be used to enable Nashorn-specific scripting extensions. This
is the subject of the next subsection.
n
Scripting with jjs
The jjs shell can be a good way to test out some basic JavaScript, or to work inter‐
actively with an unfamiliar JavaScript package (e.g., when learning it). However, it is
slightly hampered by lacking multiline input and other more advanced features that
are often expected when developing with languages that make heavy use of a REPL.
Instead, jjs is very suitable for noninteractive use, such as bringing up a daemon
process written in JavaScript. For use cases like this, we invoke jjs like this:
$ jjs - scripting my_script . js
This enables us to make use of the enhanced features of jjs . These include some
useful extensions, many of which make using Nashorn slightly more familiar to the
script programmer.
Scripting comments
In traditional Unix scripting, the # character is used to indicate a comment that runs
until the end of the line. JavaScript, of course, uses C/C++ style comments that
include // to indicate a comment that runs to the end of the line. Nashorn conforms
to this as well, but in scripting mode also accepts the Unix scripting style, so that
this code is perfectly legal:
# !/ usr / bin / jjs
# A perfectly legal comment in scripting mode
print ( "After the comment" );
1 JavaFX is a standard Java technology used for making GUIs—but it is outside the scope of this
topic.
 
Search WWH ::




Custom Search