Backend Development 8 min read

Managing Multiple JDK Versions with jEnv

This guide explains how to install jEnv, add and configure multiple JDK versions, set global and local JDKs per project, and integrate the tool with Maven and Gradle to ensure the correct Java version is used across diverse development environments.

Cognitive Technology Team
Cognitive Technology Team
Cognitive Technology Team
Managing Multiple JDK Versions with jEnv

Developers often need to switch between different codebases that require different Java versions, especially with the six‑month release cycle of Java. jEnv is a tool that lets you manage multiple JDK installations and assign a specific JDK to each project without altering the JAVA_HOME environment variable.

Install jEnv on Linux or macOS (Windows users need WSL or a Bash emulator) following the instructions on the jEnv homepage. Then download a JDK (e.g., from AdoptOpenJDK) as a .tar.gz archive and extract it to a directory of your choice.

To make the new JDK known to jEnv, run jenv add /path/to/jdk-15+36/ . After adding, jenv versions will list all available JDKs, including the newly added 15 and openjdk64-15 .

jEnv supports both a global JDK (used when no local version is defined) and local JDKs (specific to a folder). Set the global JDK with jenv global 11 and verify it with jenv global . For a project, navigate to its directory and run jenv local 15 , which creates a .java-version file containing the version number.

When the .java-version file is present, any java command executed in that folder uses the specified JDK; otherwise, the global JDK is used. This mechanism allows different projects to run with different Java versions.

To make Maven use the jEnv‑configured JDK, enable the Maven plugin with jenv enable-plugin maven . After that, mvn -version will report the local JDK (e.g., Java 15). Similarly, enable the Gradle plugin with jenv enable-plugin gradle so Gradle automatically picks up the local JDK.

If the wrong Java version is still selected, enable the export plugin via jenv enable-plugin export to ensure JAVA_HOME is set correctly for wrapper scripts like ./gradlew or ./mvnw .

In conclusion, jEnv provides a convenient way to manage multiple JDKs across projects, allowing you to set the desired JDK per directory with jenv local <version> and avoid version conflicts in Java development.

JavaGradleMavendevelopment toolsJDK managementjEnv
Cognitive Technology Team
Written by

Cognitive Technology Team

Cognitive Technology Team regularly delivers the latest IT news, original content, programming tutorials and experience sharing, with daily perks awaiting you.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.