TIL how to run JShell on Mac OS X when both Java 8 and Java 9 are installed.
In short: what is JShell?
JShell is one of the new features in Java 9. It is a REPL (Read Evaluate Print Loop) for Java, which evaluates declarations, statements, and expressions as they are entered and immediately shows the results.
Let's run it!
I currently have both Java 8 and Java 9 installed on my Mac. Note that my
JAVA_HOME points to Java 8.
$ java -version $ java version "1.8.0_121" $ Java(TM) SE Runtime Environment (build 1.8.0_121-b13) $ Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
Let's try to run JShell:
$ jshell $ Unable to locate an executable at "/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/bin/jshell" (-1)
Hmm. In order to run JShell we must go to the place where the JShell executable is located:
$ cd /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/bin/
Now we can run JShell, hooray! 🎉
$ ./jshell | Welcome to JShell -- Version 9.0.1 | For an introduction type: /help intro jshell>
Have fun experimenting.