Community
Participate
Working Groups
it would be great if eclipse JDT would support shebang style scripting of java. https://blog.codefx.org/java/scripting-java-shebang/ #!java --source 11 import java.util.Arrays; public class script { public static void main(String[] args) { System.out.println("Hello, Java scripts!"); Arrays.stream(args) .forEach(arg -> System.out.println(arg)) } helloworld example, save this as helloworld and chmod +x the file, now you can do ./helloworld. The following are issues I bumped into trying to use eclipse with such java class. 1) if file is named .java and in a java project with folder as root folder then content assist etc. works but complains about the shebang (!#) at top. 2) debugging is possible using connect to remote javavm but source lookup does not work 3) found no way to run this script from launch configuration using java launcher.
That would be cool, yes. For the "#!java --source 11" we could contribute a content describer that "detects" this as "Java" content type, even it is called "*.sh". For the shebang error in file: we probably need to change some parser rules? For running / debugging: I believe as soon as we "know" it is a JavaElement containing "main", we will offer the run/debug possibility.
for what it is worth since I opened this issue I created jbang (https://github.com/maxandersen/jbang) and during that i realized you don't actually need the #! style, you can just do: //usr/bin/env java "$0" "$@" ; exit $? import java.util.Arrays; public class script { public static void main(String[] args) { System.out.println("Hello, Java scripts!"); Arrays.stream(args) .forEach(arg -> System.out.println(arg)); } } This is similar to how golang solves it. I would say with that realization it is not really required to support it as its afaik not even part of JLS but just a "quick hack" in the java binary.