eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – LJB – NPI EA (cat = Core Java)
announcement - icon

Code your way through and build up a solid, practical foundation of Java:

>> Learn Java Basics

1. Introduction

With every new release cycle of Java, we might need to manage multiple parallel versions of the Software Development Kits (SDKs) in our environment. So setting and managing the JAVA_HOME path variable can become a real pain at times.

In this tutorial, we’ll see how jEnv can help manage multiple different versions of JDK installations.

2. What Is jEnv?

jEnv is a command line tool that helps us manage multiple JDK installations. It basically sets JAVA_HOME inside our shell in a way that can be set globally, locally to the current working directory, or per shell.

It lets us quickly switch between different Java versions. This is particularly helpful when working with multiple applications having different Java versions.

It’s worth noting that jEnv doesn’t install the Java JDK for us. Instead, it just helps us conveniently manage multiple JDK installations.

Further, let’s deep dive into jEnv installation and review its most common commands.

3. Installing jEnv

jEnv supports Linux and MacOS operating systems. Moreover, it supports Bash and Zsh shells. Let’s begin by installing it using the terminal:

On MacOS, we can simply install jEnv using Homebrew:

$ brew install jenv

On Linux, we can install jEnv from the source:

$ git clone https://github.com/jenv/jenv.git ~/.jenv

Next, let’s add the installed jenv command to the path based on the shell being used.

Adding PATH entry for Bash shell:

$ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(jenv init -)"' >> ~/.bash_profile

Adding PATH entry for Zsh shell:

$ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.zshrc
$ echo 'eval "$(jenv init -)"' >> ~/.zshrc

Lastly, to verify the jEnv installation, we make use of the jenv doctor command. On MacOS, the command would display the following:

$ jenv doctor
[OK]	No JAVA_HOME set
[ERROR]	Java binary in path is not in the jenv shims.
[ERROR]	Please check your path, or try using /path/to/java/home is not a valid path to java installation.
	PATH : /opt/homebrew/Cellar/jenv/0.5.4/libexec/libexec:/Users/jenv/.jenv/shims:/Users/user/.jenv/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
[OK]	Jenv is correctly loaded

This indicates that jenv is correctly installed and loaded, but Java isn’t yet installed.

Further, let’s take a look at how we can install and manage multiple JDK versions.

4. Managing JDK Installations

Let’s start by setting up a JDK version. We can install the JDK with one of the available package managers like brew, yum, or apt. Alternatively, we can also download the JDK and put it in some folder.

The good thing about jEnv is that we don’t need to install the JDK via a package manager. We can simply download a JDK and put it into a folder somewhere.

4.1. Adding a JDK to jEnv

Firstly, to use the new JDK with jEnv, we need to tell jEnv where to locate it. To do this, we make use of the jenv add command and specify the path to the JDK:

$ jenv add /Library/Java/JavaVirtualMachines/openjdk-8.jdk/Contents/Home/
openjdk8-1.8.0.332 added
1.8.0.332 added
1.8 added

This will add JDK 8 to jEnv. Each version is available under three different names. Let’s run jenv doctor again to confirm the JDK setup:

$ jenv doctor
[OK]	No JAVA_HOME set
[OK]	Java binaries in path are jenv shims
[OK]	Jenv is correctly loaded

We can see that jEnv now recognizes the configured JDK.

Further, let’s list all the available JDKs with jEnv using the jenv versions command:

$ jenv versions
* system (set by /Users/user/.jenv/version)
  1.8
  1.8.0.332
  openjdk64-1.8.0.332

This lists all the JDK registered with jEnv. In our case, we have JDK 8 configured with jEnv.

To demonstrate using multiple JDKs, let’s install one more JDK version – 11 and configure it with jEnv:

$ jenv add /Library/Java/JavaVirtualMachines/openjdk-11.jdk/Contents/Home/
openjdk64-11.0.15 added
11.0.15 added
11.0 added
11 added

Lastly, Running jenv versions command now will list both the configured JDK versions:

$ jenv versions
* system (set by /Users/avinb/.jenv/version)
  1.8
  1.8.0.332
  11
  11.0
  11.0.15
  openjdk64-11.0.15
  openjdk64-1.8.0.332

Evidently, we now have both the JDK versions configured with jEnv.

4.2. Managing JDK Versions Using jEnv

jEnv supports three types of JDK configuration:

  • Global – JDK that will be used if we type the java command into the command line anywhere on our computer.
  • Local – JDK that is configured for a specific folder only. Typing the java command in the folder will use the local JDK version instead of the global JDK version.
  • Shell – JDK that will be used only for the current shell instance.

Firstly, let’s check the version of the global JDK:

$ jenv global
system
This command outputs “system” denoting that the system-installed JDK will be used as a global JDK. Let’s set the global JDK version to JDK 11:
$ jenv global 11

Checking the global version now will display JDK 11:

$ jenv global
11

Next, let’s look at how we can set a local JDK version.

For example, let’s say we have a sample project in the ~/baeldung-project directory which uses JDK 8. Let’s cd into this directory and check the local JDK version for this project:

$ jenv local
jenv: no local version configured for this directory

This error message indicates that we have not yet set any local JDK version for this directory. Running the jenv version command in the absence of a local JDK version will display the global JDK version. Let’s set a local JDK version for this directory:

$ jenv local 1.8

This command sets the local JDK in the ~/baeldung-project directory. Setting the local JDK basically creates a file called .java-version in the current directory. The file contains the local JDK version “1.8″ which we have set.

Running the jenv version command again in this directory will now output JDK 8. Let’s check the local JDK version set in this directory:

$ jenv local
1.8

Lastly, to set the JDK version for a particular shell instance, we use the jenv shell command:

$ jenv shell 1.8

This sets the JDK version for the current shell instance and overrides any local and global JDK version already set.

4.3. Configure jEnv with Maven and Gradle

As we all know, tools like Maven and Gradle use the system JDK to run. It does not use the jEnv configured JDK. In order to ensure that jEnv works properly with Maven and Gradle, we have to enable their respective plugins.

For Maven, we will enable the jEnv maven plugin:

$ jenv enable-plugin maven

Similarly, for Gradle, we will enable the jEnv gradle plugin:

$ jenv enable-plugin gradle

Running the Maven and Gradle commands now will use the jEnv-specific JDK versions instead of the system JDK.

Note that, sometimes jEnv might not pick the correct JDK version, and we might end up with errors. For such cases, we might have to enable the jEnv export plugin:

$ jenv enable-plugin export

In other words, this plugin will ensure that the JAVA_HOME variable is set correctly.

Also, SDKMAN is an alternative tool for managing JDKs, among other tools.

5. Conclusion

In this article, we first looked at what jEnv is and how we could install it.

We then looked at how jEnv can help us configure and manage different JDK installations conveniently. Next, we saw how we can quickly use a global, local, and shell-specific JDK version using jEnv. This will particularly help us when working with multiple different projects having different JDK versions.

Finally, we looked at how jEnv can be configured to work with build tools like Maven and Gradle.

Baeldung Pro – NPI EA (cat = Baeldung)
announcement - icon

Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:

>> Explore a clean Baeldung

Once the early-adopter seats are all used, the price will go up and stay at $33/year.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – LS – NPI (cat=Java)
announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

eBook Jackson – NPI EA – 3 (cat = Jackson)
2 Comments
Oldest
Newest
Inline Feedbacks
View all comments