A Quick Start with JAVA REPL - JSHELL using Docker
JAVA 9 introduced the much awaited JAVA REPL — JSHELL. In order to get quickly started with JAVA 9 or later, without upsetting the local setups that are in place, I recommend running JAVA in a container using Docker.
Steps to setup JAVA in a Container Using Docker
- [Step 0 : pre-requisite ] Get Docker — either set up in your system https://www.docker.com/get-docker or get a cloud hosted trial from https://dockertrial.com/register/
- [ Step 1 : ] Run Docker container with JAVA 9 (you can also run the latest version by replacing 9 with latest)
docker run -it openjdk:9-jdk
This will spin up a new container, in JSHELL. This is great for fiddling with JSHELL. Use /exit to exit from JSHELL — it will also stop the container
In case, you wish to experiment with all the new features(beyond the amazing JSHELL), you may wish to spin up the new container in LINUX SHELL, and then use JAVA 9 JDK’s CLI commands (and even move into JSHELL). You can achieve this by:
docker run -it openjdk:9-jdk /bin/sh
Use /exit to exit from JSHELL and the exit to exit from the LINUX SHELL — it will also stop the container.
Why do I use OpenJDK as preferred choice of JAVA for Docker Image ?
Oracle Licensing prevents us from redistributing the official JDK.
Why does the container starts in JSHELL by default ?
The answer lies in the DockerFile, it exposes only the JSHELL as the default command to run once the container is up.