Java the weed

A longer story ...

Java is like a weed: a plant whose growth cannot be controlled. As in real life, you have to check from time to time where it has installed itself and you have to remove it manually, because - at least in my Windows machine - not one JAVA SDK is listed under Apps.

The problem with that is that you never know which Java SDK (or run-time) is used when you use Java. The first one installed, the last one installed, the one with the highest version number ... what if there are two distributions with the same version, which one is updated automatically and so on.

Observations

One day, I recognized a growing list of SDKs in my IntelliJ project:

Java SDKs in the project - found and added by IntelliJ

The first action I took was to search for "java.exe" which gave me some insight where to look for weed.

Searching for "java.exe" - using Everything

Alternatively, on Windows you can run where /R groovy.bat and where /R java.exe to find all SDK locations on your machine.

Actually, I wanted

  • one Java SDK and distribution (I use Amazon Corretto v23)

  • the ATOM SDK: C:\Program Files\Boomi AtomSphere\LocalAtom\jre\bin

  • Some applications, especially JetBrains Apps like IntelliJ, install their own, local run-time,, which you will want to keep!

Confusion

There is no other way to check for Java installations on your machine then searching for "java.exe" - omg!

You may use where java on the command-line or you want to check the JAVA_HOME environment variable:

C:\> where java
C:\Program Files\Amazon Corretto\jdk21.0.6_7\bin\java.exe

C:\> set JAVA_HOME
JAVA_HOME=C:\Users\marku\.jdks\corretto-23.0.1

and you will be confused even more!

Nothing is listed under "Apps" (Windows)

Get rid of it

Close IntelliJ and all other applications that might lock Java.

  • Pick all the paths containing a java.exe which you don't want.

  • Delete these directories using a console window with ADMIN rights.

rmdir /s /q "C:\Program Files\Amazon Corretto\jdk21.0.6_7\bin\"
rmdir /s /q "C:\Users\marku\.jdks\corretto-23.0.1\bin"
rmdir /s /q "C:\Users\marku\.jdks\corretto-23.0.2\bin"
rmdir /s /q "C:\Users\marku\.jdks\jbr-17.0.12\bin"
rmdir /s /q "C:\Users\marku\.jdks\openjdk-23.0.1\bin"
Gradle

Gradle is a Java build tool. You may have it or not but you may notice it is even worse than Java:

.gradle Cache files

I delete my .gradle cache folder from time to time (incl. the included Java distributions) to get a fresh Gradle setup: rmdir /s /q "V:\packages\.gradle". The next time I use Gradle it downloads and installs back automatically but I got rid of all the old and unused versions that were littering my computer.

For example, the ScriptEaseLib is built with Gradle. Every time I build it, the Gradle toolchain is downloaded if it does not exist. It takes a minute or two ...

Gradle is downloading

Clean! Start over! Clean install!

  • Close all JAVA apps

  • Close IntelliJ

    • Close all JetBrains apps, incl. ToolBox

  • Check Task Manager that Java isn't running anymore

  • Alternatively: log-off and log-on again

Find your preferred distribution, for example: Amazon Corretto 23.

Ensure you are running a complete installation incl. environment variables etc.

Unfortunately there are two (Windows) environment variables: for the current user and for system. The user setting has preference and the Corretto installation sets the system variable. Delete the user's JAVA_HOME and go with the just installed system setting:

Windows environment settings

Fix IntelliJ

IntelliJ will now list orphaned references:

Orphaned Java SDKs in IntelliJ
  • Leave the ATOM JDK and remove all other entiries.

  • Add the one and only that you have just installed

  • Fix your Project Settings

* Make sure all your modules (normally there is only one) use the Project SDK

Final Checks

Open a new console window! If you had an open console, this has not recognized all the changes you made!

c:\> where java
C:\Program Files\Amazon Corretto\jdk23.0.2_7\bin\java.exe

c:\> set JAVA_HOME
JAVA_HOME=C:\Program Files\Amazon Corretto\jdk23.0.2_7

Last updated