Currently I have a java project where I should support different version of it, which use different version of Java (and some tools, like Ant). Depends on issue tickets I need to handle both java version (7 and 8) and pretty often switch between them. Can someone suggest the best way to handle it easier? I'm working on Windows 7, so I wrote such bat-file for switching ("switch_java.bat"):
@ECHO OFF
set changeToNewVersion=%1
IF "%changeToNewVersion%"=="true" (
setx /M ANT_HOME "c:\Program Files\Ant\apache-ant-1.9.4"
setx /M JAVA_HOME "c:\Program Files\Java\jdk1.8.0_51"
) ELSE IF "%changeToNewVersion%"=="false" (
setx /M ANT_HOME "c:\Program Files\Ant\apache-ant-1.8.3"
setx /M JAVA_HOME "c:\Program Files\Java\jdk1.7.0_79"
) ELSE (
echo ERROR: Enter key!
)
But maybe there is more optimal solution?
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
Add a new Java environment (requires absolute path)
jenv add <name> <path>
Example: jenv add jdk15 D:\Programme\Java\jdk-15.0.1
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"
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="
Change your java version globally
jenv change <name>
Example: jenv change jdk15
Always use this java version in this folder
jenv local <name>
Example: jenv local jdk15
Clear the java version for this folder
jenv local remove
Example: jenv local remove
List all your Java environments
jenv list
Example: jenv list
Remove an existing JDK from the JEnv list
jenv remove <name>
Example: jenv remove jdk15
Enable the use of javac, javaw or other executables sitting in the java directory
jenv link <Executable name>
Example: jenv link javac
Uninstall jenv and automatically restore a Java version of your choice
jenv uninstall <name>
Example: jenv uninstall jdk17
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With