Last active
February 7, 2019 23:39
-
-
Save headius/a2e858daa0a5f62f112de57684c3d1c3 to your computer and use it in GitHub Desktop.
Wouldn't it be nice if Java allowed normal shebangs?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Shebangs are supported in Java 11, but only if: | |
# * You pass "--source 11" to a fully-qualifed `java` command. | |
# * The script does *not* end with .java. | |
[] ~/projects/jruby $ cat Blah.java | |
public class Blah { | |
public static void main(String[] args) { | |
return; | |
} | |
} | |
[] ~/projects/jruby $ java Blah.java | |
[] ~/projects/jruby $ diff Blah.java Blah2.java | |
0a1 | |
> #!/usr/bin/env java | |
[] ~/projects/jruby $ ./Blah2.java | |
./Blah2.java:1: error: illegal character: '#' | |
#!/usr/bin/env java | |
^ | |
./Blah2.java:1: error: class, interface, or enum expected | |
#!/usr/bin/env java | |
^ | |
2 errors | |
error: compilation failed | |
[] ~/projects/jruby $ diff Blah2.java Blah3.java | |
1c1 | |
< #!/usr/bin/env java | |
--- | |
> #!/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home/bin/java --source 11 | |
[] ~/projects/jruby $ ./Blah3.java | |
./Blah3.java:1: error: illegal character: '#' | |
#!/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home/bin/java --source 11 | |
^ | |
./Blah3.java:1: error: class, interface, or enum expected | |
#!/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home/bin/java --source 11 | |
^ | |
2 errors | |
error: compilation failed | |
[] ~/projects/jruby $ mv Blah3.java blah4 | |
[] ~/projects/jruby $ ./blah4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment