Start using Java 9 shell — jshell with docker
1 min readDec 5, 2016
REPL has finally arrived in Java 9. This is how I got started with jshell without hurting my local Java 8 setup by using Docker. I assume you’re a developer with a Unix/Linux shell(highly recommend zsh with oh-my-zsh).
- Get docker — https://docs.docker.com/engine/installation/ and start the daemon (in Mac OS X docker starts once you install the Docker App)
2. Pull the OpenJDK jdk 9 early access release image from docker hub
$ docker pull openjdk:9-jdk
3. Run the Docker container with the following:
$ docker run -it openjdk:9-jdk /bin/jshell
Dec 04, 2016 11:57:55 PM java.util.prefs.FileSystemPreferences$1 run
INFO: Created user preferences directory.
| Welcome to JShell -- Version 9-Debian
| For an introduction type: /help introjshell>
Voila! The jshell opens up in your current shell.
4. [Extra-Credit] Create a shell script to do step 3 and add it to /usr/local/bin
to just type in jshell and get the java 9 shell from your *SH terminal:
This is how my /usr/local/bin/jshell
script looks like:
#!/bin/zsh
docker run -it openjdk:9-jdk /bin/jshell
Happy jshelling.