Java Tools Tutorials - Herong's Tutorial Examples - v6.24, by Herong Yang
"jrunscript -f" - Run JavaScript in Batch Mode
This section provides a tutorial example on how to use 'jrunscript -f ...' to run JavaScript code in batch mode.
If you want to run JavaScript code stored in a file in batch mode, you use the "jrunscript -f ..." command.
1. Create a test JavaScript code file, While-Loop.js.
// While-Loop.js
// Copyright (c) 2018 HerongYang.com. All Rights Reserved.
//
var i, j, is_prime;
i = 3;
while ( i<=30 ) {
is_prime = true;
j = 2;
while ( j<=i/2 ) {
is_prime = i%j > 0;
if (!is_prime) break;
j++;
}
if (is_prime)
print("Found a prime number: " + i);
i += 2;
}
2. Run the JavaScript code file in batch mode with "jrunscript -f ..." command.
herong$ jrunscript -f While-Loop.js Warning: Nashorn engine is planned to be removed from a future JDK release Found a prime number: 3 Found a prime number: 5 Found a prime number: 7 Found a prime number: 11 Found a prime number: 13 Found a prime number: 17 Found a prime number: 19 Found a prime number: 23 Found a prime number: 29
Okay, running JavaScript code in batch mode with "jrunscript" is easy too!
Table of Contents
javac - The Java Program Compiler
java - The Java Program Launcher
jpackage - Binary Package Builder
javadoc - The Java Document Generator
jdeps - The Java Class Dependency Analyzer
jdeprscan - The Java Deprecated API Scanner
jcmd - The JVM Diagnostic Tool
jconsole - Java Monitoring and Management Console
jstat - JVM Statistics Monitoring Tool
jhsdb - The Java HotSpot Debugger
jvisualvm (Java VisualVM) - JVM Visual Tool
javap - The Java Class File Disassembler
keytool - Public Key Certificate Tool
►jrunscript - Script Code Shell
"jrunscript" - Run JavaScript Interactively
►"jrunscript -f" - Run JavaScript in Batch Mode
native2ascii - Native-to-ASCII Encoding Converter