Upgrading Java – How to keep applications from breaking due to changed path

Reading Time: 3 minutes

Java developers define JAVA_HOME environment variable often used by various applications. However, when you install an upgrade, it gets installed in a new folder.

Not only application using JAVA_HOME, but many applications directly detect installed jdk and select a version as default at the time of installation. Now that you have installed a newer version, you would be going to every application’s configuration and environment variable to update that path.

This, in fact, is a common issue for developers, as the SDKs are often released and installed in different folders due to some applications and even OSs needing backward compatibility. What makes it worse is the frequent updates, which means, for even a minor upgrade, this process is to be repeated.

Not amused ? Me neither.

So I am going to show you how you can get rid of this tedious task using very simple steps.

All you need to do is, create symlink and place it under a convenient location. I create this under Java folder only.

To create symlink in windows, open command prompt using admin privileges.

Navigate to folder you want this symlink created in.

C:\WINDOWS\system32>CD "C:\Program Files\Java"

Then, create the symlink using this command

C:\Program Files\Java>Mklink /D current "C:\Program Files\Java\jdk-14\"

In above command, /D signifies the symlink is for a directory. “current” is the name you want for the symlink. And, at the last is the path of the directory you want the symlink to target to.

Press enter and you will see a symlink created under java folder.

Now, instead of the below path

C:\Program Files\Java\jdk-13.0.1

You can use this path anywhere you want

C:\Program Files\Java\current

For example, look below at how my environment variable “JAVA_HOME” looks like.

With this, when you will upgrade to newer java versions, all you have to do is, replace this symlink with a new one pointing towards new jdk folder. Restart the application, eclipse for example, and it will now pick and use the latest java version .

That’s it. Though I have tested this on a Windows System for Java SDK, this method should also work on linux and mac based systems, as well as for SDKs other than Java also.

Leave a Reply