There is a Github tool for windows. I'm using it myself and it's really nice.
The maintainer is normally responding very fast if you have a problem

Usage (Note: local overwrites change. use overwrites local)

  1. Add a new Java environment (requires absolute path)
    jenv add <name> <path>
    Example: jenv add jdk15 D:\Programme\Java\jdk-15.0.1

  2. Change your java version for the current session
    jenv use <name>
    Example: jenv use jdk15
    Environment var for scripting:
    ---PowerShell: $ENV:JENVUSE="jdk17"
    ---CMD/BATCH: set "JENVUSE=jdk17"

  3. Clear the java version for the current session
    jenv use remove
    Example: jenv use remove
    Environment var for scripting:
    ---PowerShell: $ENV:JENVUSE=$null
    ---CMD/BATCH: set "JENVUSE="

  4. Change your java version globally
    jenv change <name>
    Example: jenv change jdk15

  5. Always use this java version in this folder
    jenv local <name>
    Example: jenv local jdk15

  6. Clear the java version for this folder
    jenv local remove
    Example: jenv local remove

  7. List all your Java environments
    jenv list
    Example: jenv list

  8. Remove an existing JDK from the JEnv list
    jenv remove <name>
    Example: jenv remove jdk15

  9. Enable the use of javac, javaw or other executables sitting in the java directory
    jenv link <Executable name>
    Example: jenv link javac

  10. Uninstall jenv and automatically restore a Java version of your choice
    jenv uninstall <name>
    Example: jenv uninstall jdk17

  11. Automatically search for java versions to be added
    jenv autoscan ?<path>?
    Example: jenv autoscan "C:\Program Files\Java"
    Example: jenv autoscan // Will search entire system

https://github.com/FelixSelter/JEnv-for-Windows

Answer from Huhngut on Stack Overflow
🌐
GitHub
github.com › FelixSelter › JEnv-for-Windows
GitHub - FelixSelter/JEnv-for-Windows: Change your current Java version with one line · GitHub
JEnv allows you to change your current JDK Version. This is helpful for testing or if you have projects requiring different versions of java · For example you can build a gradle project which requires java8 without changing your environment ...
Starred by 916 users
Forked by 106 users
Languages   PowerShell 97.1% | Batchfile 2.9%
🌐
Jenv
jenv.be
jEnv - Manage your Java environment
$ jenv add /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home oracle64-1.6.0.39 added $ jenv add /Library/Java/JavaVirtualMachines/jdk17011.jdk/Contents/Home oracle64-1.7.0.11 added
🌐
Medium
medium.com › javarevisited › manage-java-versions-with-jenv-6b8228552661
Manage Java Versions with jEnv. Master your Java Environment | by Jayson GCS | Javarevisited | Medium
September 11, 2023 - jEnv supports Linux and MacOS only, but it is possible to install it on Windows by installing Windows Subsystem for Linux.
Top answer
1 of 3
6

There is a Github tool for windows. I'm using it myself and it's really nice.
The maintainer is normally responding very fast if you have a problem

Usage (Note: local overwrites change. use overwrites local)

  1. Add a new Java environment (requires absolute path)
    jenv add <name> <path>
    Example: jenv add jdk15 D:\Programme\Java\jdk-15.0.1

  2. Change your java version for the current session
    jenv use <name>
    Example: jenv use jdk15
    Environment var for scripting:
    ---PowerShell: $ENV:JENVUSE="jdk17"
    ---CMD/BATCH: set "JENVUSE=jdk17"

  3. Clear the java version for the current session
    jenv use remove
    Example: jenv use remove
    Environment var for scripting:
    ---PowerShell: $ENV:JENVUSE=$null
    ---CMD/BATCH: set "JENVUSE="

  4. Change your java version globally
    jenv change <name>
    Example: jenv change jdk15

  5. Always use this java version in this folder
    jenv local <name>
    Example: jenv local jdk15

  6. Clear the java version for this folder
    jenv local remove
    Example: jenv local remove

  7. List all your Java environments
    jenv list
    Example: jenv list

  8. Remove an existing JDK from the JEnv list
    jenv remove <name>
    Example: jenv remove jdk15

  9. Enable the use of javac, javaw or other executables sitting in the java directory
    jenv link <Executable name>
    Example: jenv link javac

  10. Uninstall jenv and automatically restore a Java version of your choice
    jenv uninstall <name>
    Example: jenv uninstall jdk17

  11. Automatically search for java versions to be added
    jenv autoscan ?<path>?
    Example: jenv autoscan "C:\Program Files\Java"
    Example: jenv autoscan // Will search entire system

https://github.com/FelixSelter/JEnv-for-Windows

2 of 3
1

IMO, it's primarily opinion-based question, but I don't think, that you may find a better solution, then a batch scripts to do that.

As from my point of view, it could be not very usefull to make a script with parameters, because it should be executed via command line or from another bat file.

So, you can create 2 separate bat files, one to set jdk 1.7 and the second is to set jdk 1.8. Or you can modify your script, to determine the current version and set another one. In both cases, you can simply call execute a bat file without providing any additional parameters.

🌐
GitHub
github.com › jenv › jenv
GitHub - jenv/jenv: Manage your Java environment · GitHub
Use jenv global VERSION to set a global, default Java version: ... When you next open a shell or terminal window, this version of Java will be the default.
Starred by 6.6K users
Forked by 398 users
Languages   Shell 99.0% | Dockerfile 1.0%
🌐
Whywhathow
whywhathow.github.io › jenv
JEnv - Java Environment Manager
JEnv - Java Environment Manager · Minimal RAM Usage 最小内存占用 · No waiting, no downtime 无等待,无停机时间 · Smart path management 智能路径管理 · Built for Windows users 专为Windows用户打造 · Check version and help information 查看版本和帮助信息 ·
Find elsewhere
🌐
Bekk Christmas
bekk.christmas › post › 2022 › 16 › java-versions-are-easier-with-jenv
Java versions are easier with jEnv | Bekk Christmas
November 7, 2024 - No tool is complete without a set of addons, is it? jenv comes with a set of addons, and some of them are a must have. The plugin export handles setting JAVA_HOME, a variable used by many a program to refer to the directory of your Java executable. Another key plugin, should you use maven, is the maven-plugin. Of course, gradle comes with a plugin too! ... Windows-developers: rejoice!
🌐
Reddit
reddit.com › r/java › manage multiple jdks on mac os, linux and windows wsl2
r/java on Reddit: Manage Multiple JDKs on Mac OS, Linux and Windows WSL2
April 25, 2020 - I have been doing Java on Windows and deploying it into application servers running on UNIX environments for years, WSL hasn't changed anything on my workflow. Because that is the beauty of languages like Java, the OS is irrelevant, and doing JNI cross platform is also not a big deal, conditional compilation is a thing and JNA also exists. ... Nice article man! I did know about jEnv but I will definitely try that!
🌐
CSDN
cnblogs.com › java-six › p › 17937124
windows中使用jenv管理java多版本 - 又一岁荣枯 - 博客园
"jenv add <name> <path>" Adds a new Java-Version to JEnv which can be refferenced by the given name "jenv remove <name>" Removes the specified Java-Version from JEnv "jenv change <name>" Applys the given Java-Version globaly for all restarted shells and this one "jenv use <name>" Applys the given Java-Version locally for the current shell "jenv local <name>" Will use the given Java-Version whenever in this folder.
🌐
FreeMediaHeckYeah
fmhy.net › developer-tools
Developer Tools • freemediaheckyeah
JEnv For Windows - Change Java Version · ⁠WhichJDK - JDK Version Cheatsheet / Info · jadx - Dex to Java Decompiler · GraalVM - Advanced Multi-language JVM · Awesome HTML5 - HTML5 Resources · HTML Reference, HTML Cheat Sheet or HTML.com - HTML Guides / Cheat Sheets ·
🌐
Medium
dharma-adiputra.medium.com › jenv-a-java-environment-manager-68ee7be78285
jEnv — a 👍🏻 java environment manager | by Dharma Adiputra | Medium
August 5, 2018 - I know this XXE project must work on Java ≤ 1.7. The problem is I have installed JDK 1.8 and I do not want to uninstall it first, install JDK 1.6 then reinstall JDK 1.8 just to test if my payload is working. Fortunately, jEnv is installable through HomeBrew, and it is easy to configure.
🌐
GitHub
github.com › WhyWhatHow › jenv
GitHub - WhyWhatHow/jenv: Java Environment Mananger, build by Go.Currently work for windows, linux & macos. · GitHub
Java Environment Mananger, build by Go.Currently work for windows, linux & macos. - WhyWhatHow/jenv
Starred by 48 users
Forked by 8 users
Languages   Go 40.2% | HTML 31.6% | JavaScript 15.4% | CSS 9.2% | Python 3.6%
🌐
GitHub
github.com › FelixSelter › JEnv-for-Windows › actions
Workflow runs · FelixSelter/JEnv-for-Windows
Change your current Java version with one line. Contribute to FelixSelter/JEnv-for-Windows development by creating an account on GitHub.
Author   FelixSelter
🌐
GitHub
github.com › jenv › jenv › issues
Issues · jenv/jenv
You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert · {{ message }} There was an error while loading. Please reload this page. jenv / jenv Public ·
Author   jenv