CSR :
|
|
Relates :
|
|
Relates :
|
JEP 330 adds a mode which allows Java to be delivered in "shebang" scripts. A feature very commonly used in shebang scripts is locating the script file itself, with the Unix shell using the syntax "$0" (a special parameter name). Shebang scripts coded in Java will have the same kinds of occasions to locate themselves, and so there should be a hook for obtaining the pathname of the script file, from code executing in the script itself. (Uses of the script pathname are not specific to the Unix shell or to any particular language; they include issuing diagnostics and locating resource files packaged with the script. These uses potentially apply to Java scripts, even the simple ones envisioned by JEP 330.) This requirement can be met almost trivially, by picking a property name, such as "source", and ensuring that the JVM (when invoked in source-file mode) binds the pathname (or perhaps URL) of the source file the given property name, as if by the JVM command line option "-Dsource=path/to/script/file". The script can easily pick up this pathname using the System.getProperty API point, as long as there is an agreed-upon property name. Workaround: Use a carefully crafted shell script wrapper to launch the JVM when an explicit "-Dsource=$0" argument. See http://cr.openjdk.java.net/~jrose/scripts/myshebang.txt
|