{"id":5524,"date":"2015-12-31T17:32:36","date_gmt":"2015-12-31T09:32:36","guid":{"rendered":"http:\/\/rmohan.com\/?p=5524"},"modified":"2015-12-31T17:32:36","modified_gmt":"2015-12-31T09:32:36","slug":"java-versions-on-windows","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=5524","title":{"rendered":"JAVA VERSIONS ON WINDOWS"},"content":{"rendered":"<h2>Slow way<\/h2>\n<ol>\n<li>Open your<span class=\"Apple-converted-space\">\u00a0<\/span><b>Start Menu<\/b><\/li>\n<li>Go to<span class=\"Apple-converted-space\">\u00a0<\/span><b>All Programs<\/b><\/li>\n<li>Go to<span class=\"Apple-converted-space\">\u00a0<\/span><b>Accessories<\/b><\/li>\n<li>Right-click<span class=\"Apple-converted-space\">\u00a0<\/span><b>Command Prompt<\/b><\/li>\n<li>Select<span class=\"Apple-converted-space\">\u00a0<\/span><b>Run as administrator<\/b><\/li>\n<li>Answer<span class=\"Apple-converted-space\">\u00a0<\/span><b>Yes<\/b><span class=\"Apple-converted-space\">\u00a0<\/span>to the following User Account Control question<\/li>\n<\/ol>\n<ol>\n<li>Go\/Make somewhere you want this.\n<div class=\"codecolorer-container dos default\">\n<div class=\"dos codecolorer\"><span class=\"sy0\">&gt;<\/span><span class=\"Apple-converted-space\">\u00a0<\/span>c:<br \/>\n<span class=\"sy0\">&gt;<\/span><span class=\"Apple-converted-space\">\u00a0<\/span><span class=\"kw3\">mkdir<\/span><span class=\"Apple-converted-space\">\u00a0<\/span>\\dev\\java<br \/>\n<span class=\"sy0\">&gt;<\/span><span class=\"Apple-converted-space\">\u00a0<\/span><span class=\"kw3\">cd<\/span><span class=\"Apple-converted-space\">\u00a0<\/span>\\dev\\java<\/div>\n<\/div>\n<\/li>\n<li>Set up the symlinks\n<div class=\"codecolorer-container dos default\">\n<div class=\"dos codecolorer\"><span class=\"sy0\">&gt;<\/span><span class=\"Apple-converted-space\">\u00a0<\/span>mklink \/d 1.5 &#8220;c:\\Program Files\\Java\\jdk1.5.0_22&#8221;<br \/>\n<span class=\"sy0\">&gt;<\/span><span class=\"Apple-converted-space\">\u00a0<\/span>mklink \/d 1.7 &#8220;c:\\Program Files\\Java\\jdk1.7.0&#8221;<br \/>\n<span class=\"sy0\">&gt;<\/span><span class=\"Apple-converted-space\">\u00a0<\/span>mklink \/d 1.6 &#8220;c:\\Program Files\\Java\\jdk1.6.0_27&#8221;<br \/>\n<span class=\"sy0\">&gt;<\/span><span class=\"Apple-converted-space\">\u00a0<\/span>mklink \/d active 1.7<\/div>\n<\/div>\n<\/li>\n<li>Set your JAVA_HOME and PATH environment variables. *\n<div class=\"codecolorer-container dos default\">\n<div class=\"dos codecolorer\">setx JAVA_HOME &#8220;C:\\dev\\java\\active&#8221; \/m<br \/>\nsetx PATH &#8220;<span class=\"sy0\">%<\/span><span class=\"re2\">JAVA_HOME<\/span><span class=\"sy0\">%<\/span>\\bin;<span class=\"sy0\">%<\/span><span class=\"re2\">PATH<\/span><span class=\"sy0\">%<\/span>&#8221; \/m<\/div>\n<\/div>\n<\/li>\n<\/ol>\n<div class=\"my-note\">*<span class=\"Apple-converted-space\">\u00a0<\/span>The second command assumes you don\u2019t have Java in your PATH already. If you do, you should edit it the usual way instead. Also note that if JAVA_HOME is already set, it will be expanded in the second command.<\/div>\n<p>Now open up a new regular command prompt and run the following.<\/p>\n<div class=\"codecolorer-container dos default\">\n<div class=\"dos codecolorer\"><span class=\"sy0\">&gt;<\/span><span class=\"Apple-converted-space\">\u00a0<\/span>java -version<br \/>\n<span class=\"sy0\">&gt;<\/span><span class=\"Apple-converted-space\">\u00a0<\/span>mvn &#8211;version<\/div>\n<\/div>\n<p>Both (skip mvn if you don\u2019t have maven installed) should report Java version 1.7.<\/p>\n<h2>Swapping<\/h2>\n<p>So, let\u2019s say we want to change to java 1.5, we just need to run the following in an elevated command prompt.<\/p>\n<div class=\"codecolorer-container dos default\">\n<div class=\"dos codecolorer\"><span class=\"sy0\">&gt;<\/span><span class=\"Apple-converted-space\">\u00a0<\/span><span class=\"kw3\">cd<\/span><span class=\"Apple-converted-space\">\u00a0<\/span>\\dev\\java<br \/>\n<span class=\"sy0\">&gt;<\/span><span class=\"Apple-converted-space\">\u00a0<\/span><span class=\"kw3\">rmdir<\/span><span class=\"Apple-converted-space\">\u00a0<\/span>active<span class=\"Apple-converted-space\">\u00a0<\/span><span class=\"sy0\">&amp;&amp;<\/span><span class=\"Apple-converted-space\">\u00a0<\/span>mklink \/d active 1.5<\/div>\n<\/div>\n<p>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\u2019t even have to restart the command prompt.<\/p>\n<h3>Shortcut<\/h3>\n<p>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.<\/p>\n<div class=\"codecolorer-container dos default\">\n<div class=\"dos codecolorer\"><span class=\"sy0\">@<\/span><span class=\"kw3\">echo<\/span><span class=\"Apple-converted-space\">\u00a0<\/span>off<br \/>\n<span class=\"kw3\">cd<\/span><span class=\"Apple-converted-space\">\u00a0<\/span>\\dev\\java<span class=\"Apple-converted-space\">\u00a0<\/span><span class=\"sy0\">&amp;&amp;<\/span><span class=\"Apple-converted-space\">\u00a0<\/span><span class=\"kw3\">rmdir<\/span><span class=\"Apple-converted-space\">\u00a0<\/span>active<span class=\"Apple-converted-space\">\u00a0<\/span><span class=\"sy0\">&amp;&amp;<\/span><span class=\"Apple-converted-space\">\u00a0<\/span>mklink \/d active<span class=\"Apple-converted-space\">\u00a0<\/span><span class=\"sy0\">%<\/span><span class=\"re2\">~1<\/span><\/div>\n<\/div>\n<p>You could then create a short cut to for example<span class=\"Apple-converted-space\">\u00a0<\/span><code class=\"codecolorer text default\"><span class=\"text\">c:\\dev\\java\\swap.bat 1.5<\/span><\/code>, set it to run as administrator, and you\u2019d have a two click solution to change the Java version to 1.5. I created one shortcut for each version.<\/p>\n<p>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<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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. &gt; c: &gt; mkdir \\dev\\java &gt; cd \\dev\\java Set up the symlinks &gt; mklink \/d 1.5 &#8220;c:\\Program Files\\Java\\jdk1.5.0_22&#8221; &gt; mklink \/d [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5524"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5524"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5524\/revisions"}],"predecessor-version":[{"id":5525,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5524\/revisions\/5525"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5524"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5524"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}