Slow way
- Open your Start Menu
- Go to All Programs
- Go to Accessories
- Right-click Command Prompt
- Select Run as administrator
- Answer Yes to the following User Account Control question
- Go/Make somewhere you want this.
> c:
> mkdir \dev\java
> cd \dev\java - Set up the symlinks
> mklink /d 1.5 “c:\Program Files\Java\jdk1.5.0_22”
> mklink /d 1.7 “c:\Program Files\Java\jdk1.7.0”
> mklink /d 1.6 “c:\Program Files\Java\jdk1.6.0_27”
> mklink /d active 1.7 - Set your JAVA_HOME and PATH environment variables. *
setx JAVA_HOME “C:\dev\java\active” /m
setx PATH “%JAVA_HOME%\bin;%PATH%” /m
Now open up a new regular command prompt and run the following.
> mvn –version
Both (skip mvn if you don’t have maven installed) should report Java version 1.7.
Swapping
So, let’s say we want to change to java 1.5, we just need to run the following in an elevated command prompt.
> rmdir active && mklink /d active 1.5
If you now repeat the version checks we did in our regular command prompt they should both report version 1.5 instead of 1.7. And we didn’t even have to restart the command prompt.
Shortcut
To prevent us from having to do this manually we could also create a simple bat file. I made one I called swap.bat which I put in the same directory as the symlinks with the following contents.
cd \dev\java && rmdir active && mklink /d active %~1
You could then create a short cut to for example c:\dev\java\swap.bat 1.5
, set it to run as administrator, and you’d have a two click solution to change the Java version to 1.5. I created one shortcut for each version.
If you have a better way, please leave a comment though. Always on the lookout for things and techniques that can make my developer life simpler
Recent Comments