JEP 330 and MemoryClassLoader.getResourceAsStream
jonathan.gibbons at oracle.com
Sat Aug 25 04:34:21 UTC 2018
On 8/24/18 7:27 PM, John Rose wrote:
> On Aug 24, 2018, at 5:47 PM, Jonathan Gibbons
> <jonathan.gibbons at oracle.com <mailto:jonathan.gibbons at oracle.com>> wrote:
>> The worker class that performs the source-file launcher work is
>> passed the name of the source file as an argument, but it is not
>> passed down to the source code or class file in any way.
> OK, so that's not a workaround anyway.
> As a general matter regarding script files, they often make
> use of $0 to either refer to themselves (for error reporting)
> or to access side files. The JEP points out that a shell script
> wrapper can be used to adjust the launching of the JVM,
> and it occurs to me that (1) this can be used to push the
> origin (shell "$0") into the Java program, and (2) the JEP
> allows a single file to be launched by both /bin/sh and the
> JVM—with a little finicking. Here's a proof of concept:
> The trick is to make the initial segment of the shebang file
> acceptable to both /bin/sh and the JVM's source-file reader.
> I was mildly surprised to find that it can be done with a mix
> of quotes and comment delimiters (in both languages).
> Anyway, the above POC might be useful to someone
> who wants to use the JVM's new source-file mode for
> a script that needs to refer to itself.
> I also believe that this shouldn't require a workaround at all,
> but should be somehow native to the JVM, as $0 is to
> the shell. So I also filed JDK-8209963 to track this RFE.
We could define and use a system property with the filename.
> — John
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the compiler-dev