With more and more Java releases coming up, it’ll be more interesting to manage multiple Java installations on your local environment. Different projects may require different Java versions.
The jenv project is a convenient way how to manage Java installations. It can setup local Java installations on global, directory and shell level and uses easy-to-remember Java version identifiers:
$> jenv versions
# switch to JDK 13 globally
$> jenv global 13.0
# switch to JDK 9 locally
$> cd project/
$> jenv local 9.0
$> java -version
java version "9.0.4"
Java(TM) SE Runtime Environment (build 9.0.4+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)
$> cd .. && java -version
openjdk version "13.0.1" 2019-10-15
OpenJDK Runtime Environment AdoptOpenJDK (build 13.0.1+9)
Eclipse OpenJ9 VM AdoptOpenJDK (build openj9-0.17.0, ...)
Jenv stores the local Java version in a
Jenvs works by declaring wrapper
java binaries that direct to the corresponding installation based on the context.
Shell scripts can also set a specific version via the
JENV_VERSION environment variable:
# will use JDK 13
Some of the content of this post was reposted from my newsletter issue 025.
Published on Java Code Geeks with permission by Sebastian Daschner, partner at our JCG program. See the original article here: Code Ready Containers – Getting Started with HR Employee Rewards Project in the Cloud
Opinions expressed by Java Code Geeks contributors are their own.