I wanted to check out some new features of java 11 which was released two days ago. JEP 330 states that I could launch a Java-Source-Code-Program without compiling. It should also support the usage of Shebang-Files.
Hence I have written this small Hello-World Program Test.java
:
#!/opt/java/jdk-11/bin/java --source 11
public class Test
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
I downloaded JDK 11 and extracted it to /opt/java
.
Hence the Shebang itself is working.
I.e. executing /opt/java/jdk-11/bin/java --version
gives me
openjdk 11 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)
After making Test.java
executable (using chmod +x Test.java
) the execution is failing.
I.e. ./Test.java
gives me:
./Test.java:1: error: illegal character: '#'
#!/opt/java/jdk-11/bin/java --source 11
^
./Test.java:1: error: class, interface, or enum expected
#!/opt/java/jdk-11/bin/java --source 11
^
2 errors
error: compilation failed
As soon as I remove the Shebang-Line from Test.java
and start it with /opt/java/jdk-11/bin/java --source 11 Test.java
everything is working like a charm and I get the expected output: Hello World!
My machine is running Ubuntu 17.04
.
I have linked javac
to the one from JDK 11 (i.e. executing javac -version
gives javac 11
).