Draft JEP: Launch Single-File Source-Code Programs

David Holmes david.holmes at oracle.com
Tue Feb 13 00:29:46 UTC 2018


On 13/02/2018 2:47 AM, Brian Goetz wrote:
> I don’t think that’s a concern worth worrying about.  Think about why people use shebang in the first place; they want to launch the file from the shell without saying “java” (or “python” or “bash” or …)  At this point, the file has likely entered the terminal phase of its life — it is installed as a script.  The use case of “I might want to run it standalone as a script, or compile it as part of a larger source base” seems somewhat contrived.  And for those cases, fine — run it with “java —source”, rather than shebang.  I don’t think its a bump that anyone who actually uses will be surprised at.

Ironically(?) I find that most of the files I have to execute that 
contain shebangs do not have the execute bit set (all scripts in our 
repos!) and so I have to  say "bash ...".

> The alternative — intruding this convention on the Java language syntax — is certainly a worse tradeoff.  Think of this as “launcher 90% full” rather than “language 10% empty” :)

IMHO it's a wart to have javac barf on what appears to be a regular Java 
source file because of a shebang line. Even if this is outside the scope 
of JLS, any tools in OpenJDK that can process "Java source files" should 
be specified to skip the shebang line.

Cheers,
David

> 
> 
>> On Feb 12, 2018, at 8:42 AM, Roger Riggs <Roger.Riggs at Oracle.com> wrote:
>>
>> Hi Brian,
>>
>> Yes, that works fine if that shebang  .java file is used with the launcher.
>> But what does not work is using that same .java file with javac.
>> Not a debilitating restriction but an asymmetry and a bump in the road for some.
>> And it might backflow into the build system, where some .java files should be compiled
>> with the java launcher and others with javac.
>>
>> Thanks, Roger
>>
>> On 2/12/2018 11:07 AM, Brian Goetz wrote:
>>> Its simpler than that.  There are NO changes to the JLS, nor even any (IIRC) changes to the compiler.  This is all in the command-line launcher.  This is not a Java language feature. The scope is JDK, not SE.
>>>
>>> There are really two features here:
>>>   - Launch Java source files from the java launcher.
>>>   - Additionally, strip off the #! line (if present) before passing the source to the compiler, so that the compiler sees a normal Java compilation unit when compiling, to interact nicely with native #! support.
>>>
>>>
>>>
>>>
>>>> On Feb 12, 2018, at 6:38 AM, Volker Simonis <volker.simonis at gmail.com> <mailto:volker.simonis at gmail.com> wrote:
>>>>
>>>> On Mon, Feb 12, 2018 at 3:22 PM, Roger Riggs <Roger.Riggs at oracle.com> <mailto:Roger.Riggs at oracle.com> wrote:
>>>>> Hi Jonathan,
>>>>>
>>>>> It would be  a great convenience to developers to NOT to have two types of
>>>>> java source files.
>>>>> Those that can be run directly and those that cannot. According to the JLS,
>>>>> the former can not
>>>>> be called java source files, they are something else.
>>>>>
>>>> Yes, that's exactly what I actually wanted to say. The JavaDoc analogy
>>>> can't be applied here because JavaDoc is completely transparent to the
>>>> JLS (because it is hidden within a comment). Not sure how hard and
>>>> controversial it would be tough, to change the JLS to allow and ignore
>>>> a shebang in the first line?
>>>>
>>>>> $.02, Roger
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On 2/10/2018 11:59 AM, Jonathan Gibbons wrote:
>>>>>> Volker,
>>>>>>
>>>>>> I don't see a compelling need to change the JLS to accommodate "shebang"
>>>>>> files. Most Java source files don't need the `#!` line, including any source
>>>>>> file passed to an explicit invocation of the Java launcher. The line is only
>>>>>> needed when the file is set up to be directly executed by the "shebang"
>>>>>> mechanism, in which case the line can be thought of as a "wrapper" supported
>>>>>> by the host system to enable such use. If the feature is sufficiently
>>>>>> popular, it may even be that editors will recognize and support the use of
>>>>>> such lines, in the same way that some editors recognize and support the
>>>>>> manipulation of javadoc comments, which are also not defined in the JLS
>>>>>> (beyond the basic definition of a comment in JLS 3.7).
>>>>>>
>>>>>> -- Jon
>>>>>>
>>>>>>
>>>>>> On 2/9/18 2:51 AM, Volker Simonis wrote:
>>>>>>> Hi Jonathan,
>>>>>>>
>>>>>>> that's an interesting proposal. It is just unfortunate that a Java
>>>>>>> source file starting with "shebang" won't be a legal Java file
>>>>>>> according to the Java Language Specification. Or do you plan to change
>>>>>>> the JLS to allow (and ignore) "shebang" in the first line?
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Volker
>>>>>>>
>>>>>>> On Fri, Feb 9, 2018 at 12:18 AM, Jonathan Gibbons
>>>>>>> <jonathan.gibbons at oracle.com> <mailto:jonathan.gibbons at oracle.com> wrote:
>>>>>>>> This draft JEP contains a proposal to enhance the java launcher to
>>>>>>>> support
>>>>>>>> running a
>>>>>>>> program supplied as a single file of Java source code. The program will
>>>>>>>> be
>>>>>>>> compiled
>>>>>>>> and run, without the need to explicit invoke javac, or to package up a
>>>>>>>> jar
>>>>>>>> file.
>>>>>>>>
>>>>>>>> For more details, see:
>>>>>>>>
>>>>>>>> http://openjdk.java.net/jeps/8192920 <http://openjdk.java.net/jeps/8192920>
>>>>>>>>
>>>>>>>> -- Jon
>>>>>>
>>
> 


More information about the jdk-dev mailing list