Java Version Management with jEnv
Problem: Working with several Java versions
On my first day at jambit, I picked up my laptop and installed JDK 1.8. After that, I was able to develop cool Java applications for our customers for several years without any great changes. But ever since September 2017, a new Java version has been released every 6 months.
This means that I often work on code bases compiled with different Java versions at the same time. Sometimes there are two separate projects. But it is also quite possible that there are two microservices in the same project.
The simple switching between different Java versions is therefore essential.
The solution: Quick switching with jEnv
Among many options, jEnv offers the possibility to switch between different Java versions quickly and easily.
Example
After the successful installation, you first add all Java versions available on your computer to jEnv-Configs.
Afterwards, you can set the global version in jEnv or list the existing versions at any time.
$ jenv global oracle64-13.0.2
$ jenv versions
system
oracle64-1.8.0.202
* oracle64-13.0.2 (set by /Users/jambitUser/.jenv/version)
You can always see the current Java version with jenv version and the path of executables with jenv which java.
A useful feature of jEnv is that you can set different Java versions on the directory level.
../foo:~$ jenv local oracle64-13.0.2
../bar:~$ jenv local oracle64-1.8.0.202
The directory /foo uses Java 13 and the directory /bar uses Java 8. The version for a shell session is set a similar way.
Further Aspects
- There are other similar tools such as SDKMAN and Jabba.
- jEnv is currently only available for Mac and Linux. The issue for Windows support is currently open on GitHub.
- https://www.jenv.be
- https://medium.com/@brunofrascino/working-with-multiple-java-versions-in-macos-9a9c4f15615a
- https://en.wikipedia.org/wiki/Java_version_history
---
Author: Dvin Galstian / Senior Software Architect / Business Division New Business
Download Toilet Paper #128: Java Version Management (pdf)
Want to write the next ToiletPaper? Apply at jambit!