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?
For managing different versions of Java on one environment we can use jEnv tool. After installing and adding it to Path environment variable all that need to do are:
Add all Java versions that you need to jEnv config, like:
jenv add c:\Program Files\Java\jdk1.7.0_80
Configure which JVM to use (globally, by directory or for the current shell instance):
jenv global jdk1.7.0_80