Here’s a sort of quick way to swap between Java versions on Windows without having to change any environment variables and restarting your console window and such. The short version is to create symlinks to your java versions and then a single symlink called for example ‘active’ which points to the one you want. In your environment variables java_home and path you’d then point to this ‘active’ symlink instead of the actual installation. You can then fairly quickly swap out the target of the ‘active’ symlink and, tadaa’ish, you have a different version.
- Open up an elevated command prompt.
- Go/Make somewhere you want this.
- 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
* The second command assumes you don’t 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.
Now open up a new regular command prompt and run the following.
> java -version
> mvn --version
Both (skip mvn if you don’t have maven installed) should report Java version 1.7.
So, let’s say we want to change to java 1.5, we just need to run the following in an elevated command prompt.
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.
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.
\dev\java && rmdir
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 🙂
Needed to check some XML output from a CalDAV service so I used curl, which is nice and simple. Only problem was that all the XML came back on a single long unreadable line. Turned out it wasn’t too difficult to get it formatted:
$ curl --digest --user usr:pwd -X PROPFIND | xmllint --format -
The key part here is of course the piping into
--format tells it to format the XML and the
- tells it to read the XML from standard in. The dash can be swapped with the path to an XML file, if you need to format already downloaded XML.
$ xmllint --format file.xml
Simple pimple dimple 🙂
Just a note to self in case I need this again.
> taskkill /F /IM application.exe
If you find yourself in the regular command line (cmd.exe) on Windows and you’d like to run a PowerShell script, you can do it like this:
> powershell ./example-script.ps1
Would be nice if you could just run it directly as a bat file though, right? And yes, you can! Continue reading How to run PowerShell scripts directly from Windows command line
Keep forgetting these lines, so sticking them here for future reference.
nuget spec SomeProject.csproj
Fix up created nuspec file afterwards.
Pack and Publish
nuget pack SomeProject.csproj -Build -Symbols -Properties Configuration=Release
nuget push [main nupkg file created by previous command]
This will pack and push to both the public NuGet feed and to SymbolSource.
Needed to check the HEAD of a URL on two Unix servers today. Goal was to check if routing, firewall and load balancer rules were all good. One server only had curl, and the other only had wget, so here are commands for both:
$ wget -S --spider http://geekality.net
$ curl -i -X HEAD http://geekality.net
Just a note to self, as I keep forgetting…
> mklink /d foo-current foo-1.0
> rmdir foo-current
> mklink /d foo-current foo-1.1