After installing jre1.8.0_121 on SLES11 and RedHat7, the -Dname=value option seems to be ignored by the nashorn engine when run from command line with jjs unless it is prefixed with -J.
Also the "--" argument delimiter is passed to the javascript when shebang is used.
According to online help it should work like this:
$ /usr/java/jre1.8.0_121/bin/jjs -h
jjs [<options>] <files> [-- <arguments>]
-D (-Dname=value. Set a system property. This option can be repeated.)
In the example below I have deliberately left a shebang! header in the javascript. It should not be in there but exposes another difference between u102 and u121 in how the arguments are passed to the args.js javascript.
Tracing the example without -J shows that the local args.log.properties is never read. Instead the default /usr/java/jre1.8.0_121/lib/logging.properties is used. If I replace the /usr/java/jre1.8.0_121/lib/logging.properties with my custom properties file everything is back to normal.
Is this a deliberately changed behavior in u121?
args.sh:
#!/bin/bash -x
/usr/java/jre1.8.0_102/bin/jjs -scripting -Djava.util.logging.config.file=./args.log.properties ./args.js -- arg1 arg2 $*
/usr/java/jre1.8.0_121/bin/jjs -scripting -Djava.util.logging.config.file=./args.log.properties ./args.js -- arg1 arg2 $*
args.js:
#!/usr/bin/env jjs
print (arguments);
print ($ARG[0]);
var logger = java.util.logging.Logger;
var log = logger.getLogger("args");
log.info("log output");
args.log.properties:
handlers=java.util.logging.FileHandler, java.util.logging.ConsoleHandler
.level=ALL
java.util.logging.ConsoleHandler.level=ALL
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format=%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$s %3$s %5$s%6$s%n
When run with 2 different JREs it show the below difference. The custom logging options are ignored and the argument delimiter "--" is passed as first argument to the javascipt. :
$ ./args.sh arg3
+ /usr/java/jre1.8.0_102/bin/jjs -scripting -Djava.util.logging.config.file=./args.log.properties ./args.js -- arg1 arg2 arg3
arg1,arg2,arg3
arg1
2017-02-03 11:34:59 INFO args log output
+ /usr/java/jre1.8.0_121/bin/jjs -scripting -Djava.util.logging.config.file=./args.log.properties ./args.js -- arg1 arg2 arg3
--,arg1,arg2,arg3
--
Feb 03, 2017 11:35:00 AM jdk.nashorn.internal.scripts.Script$args :program
INFO: log output
$
Adding "-J" in front of -D solves the system property issue and works with both JREs. The shebang issue remains:
$ ./args.sh arg3
+ /usr/java/jre1.8.0_102/bin/jjs -scripting -J-Djava.util.logging.config.file=./args.log.properties ./args.js -- arg1 arg2 arg3
arg1,arg2,arg3
arg1
2017-02-03 14:04:03 INFO args log output
+ /usr/java/jre1.8.0_121/bin/jjs -scripting -J-Djava.util.logging.config.file=./args.log.properties ./args.js -- arg1 arg2 arg3
--,arg1,arg2,arg3
--
2017-02-03 14:04:04 INFO args log output
$