r/programminghorror • u/Xor_Boole • Jul 04 '15
Yes, Java supports shebangs.
Let Hello.java be the following:
public class Hello {
public static void main(String... args) {
System.out.println("Hello, World!");
}
}Then, running the following shell commands:
javac Hello.java
jar -cfe Hello.jar Hello Hello.class
echo "#\!/usr/bin/env java -jar" > hello
cat Hello.jar >> hello
chmod +x hello
./hellowill produce the output "Hello, World!". Java will ignore the shebang when parsing the jar, until it hits the zip header.
Wat.
0
Upvotes
0
u/[deleted] Jul 05 '15
[deleted]