In the world of microservices, we work on different versions of Java in different microservices. It takes some effort to open the Windows configuration screen to change the Java version and run your builds. Manually doing it once in a while is ok, but what if you want to do it when you have a production defect in hand?

I found an opportunity to automate this. So I created this simple batch file to change the Java version with one click.

  • Create a new “.bat” file say for example 8_java.bat, replace your Java version path in the below code and use it in the batch file.
    @echo off
    echo Current Java is 
    echo %JAVA_HOME%
    echo Setting new Java version as
    setx -m JAVA_HOME "C:\Program Files\Java\jdk<replace_your_version>"
    echo %JAVA_HOME%
    echo Restart the session
    pause
  • Right-click the bat and Run as Administrator, restart or start a new command or power shell session to take effect.
  • Create as many batch files as per your Java version needs.

Happy Coding!