Skip to content

Instantly share code, notes, and snippets.

@ffissore
Last active September 19, 2023 10:21
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ffissore/012d7e32a096fde5266f49038c93dcaf to your computer and use it in GitHub Desktop.
Save ffissore/012d7e32a096fde5266f49038c93dcaf to your computer and use it in GitHub Desktop.
with jshell-wrapper you get runnable java scripts: it removes the heading shebang, adds an "/exit" for good measure, and passes the result to jshell
TMP=`mktemp`
tail -n +2 $@ >> $TMP
echo "/exit" >> $TMP
$JAVA_HOME/bin/jshell -q --execution local $TMP
rm $TMP
#put this file in /usr/local/bin/ or somewhere in your $PATH
federico@pawa:~$ JAVA_HOME=/opt/jvm/jdk1.9.0/ ./test.sh
Hello world!
1
2
3
4
5
6
7
8
9
#!/usr/bin/env jshell-wrapper
System.out.println("Hello world!");
IntStream.range(1, 10).forEach(System.out::println);
@rodrigoeggea
Copy link

Great wrapper script, but I changed the following line so I dont need the environment variable:
$JAVA_HOME/bin/jshell -q --execution local $TMP
to:
/usr/bin/env jshell -q --execution local $TMP

@deividgermano
Copy link

Great wrapper! I've made some changes to load lib and use in a Nginx as GCI.
I put in this project: https://github.com/deividgermano/jshell-cgi-wrapper

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment