JEP 330

Cay Horstmann cay.horstmann at sjsu.edu
Fri Jun 1 22:32:51 UTC 2018


Le 01/06/2018 à 13:26, forax at univ-mlv.fr a écrit :
> 
> 
> ------------------------------------------------------------------------
> 
>     *De: *"John Rose" <john.r.rose at oracle.com>
>     *À: *"Remi Forax" <forax at univ-mlv.fr>
>     *Cc: *"cay horstmann" <cay.horstmann at gmail.com>, "compiler-dev"
>     <compiler-dev at openjdk.java.net>
>     *Envoyé: *Jeudi 31 Mai 2018 22:55:14
>     *Objet: *Re: JEP 330
> 
>     On May 31, 2018, at 1:36 PM, Remi Forax <forax at univ-mlv.fr
>     <mailto:forax at univ-mlv.fr>> wrote:
> 
> 
>         or just put the jar near the shebang file :)
> 
> 
>     That raises an interesting question:  How does the shebang script
>     refer to a side file
>     in the same directory?  In /bin/sh we would say something like
>     "${0%/*}/side.jar".
>     I suppose there is a JVM property which exposes that command line
>     argument already;
>     if not there should be.  Then an API like java.nio.file.Path can
>     help find the side file.
> 
> 
> Amusingly, it's easier to get a jar from a server somewhere on the 
> planet than to get a jar from the same directory of a script :)
> 

Using a JVM property to load a JAR file would be very awkward--the 
script author would have to load it manually.

And no, there is no JVM property that says where the script is. user.dir 
is the current working directory, but the script is somewhere on the PATH.

You can hardcode the path to a JAR file into the shebang.

#!/path/to/java --class-path /path/to/side.jar --source version

Not attractive, I know. How are relative paths in --class-path be 
resolved? Relative to the invoking script or relative to the current 
working directory?

BTW, in Linux, everything after the /path/to/java in a shebang is passed 
to the interpreter as a single string. Will the java executable parse it 
correctly?

Cheers,

Cay

-- 

Cay S. Horstmann | http://horstmann.com | mailto:cay at horstmann.com


More information about the compiler-dev mailing list