1

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
$ 
mrmwad
  • 11
  • 3

1 Answers1

0

I don't know if this was intentional or not. But I can confirm that I ran into the problem with the -- being passed into my scripts (which do have the shebang). For the time being, I added the following to work around that problem:

if ($ARG.length > 0 && $ARG[0] == "--") {
    $ARG.shift(); // because sometimes the come through!?!
}

Just in case a later change reverts it. For clarity, my scripts actually start with:

#!/usr/bin/jjs -scripting

I wonder if the change is related to the answer here: Writing a `jjs` shebanged script that accepts just arguments

Community
  • 1
  • 1
randomScott
  • 306
  • 2
  • 8