Sunday 3 August 2014

Get OS Architecture in Java


 
Recently I came across a situation where I had to find the OS architecture and the JRE architecture i.e. I had to determine if my Windows had a 32 or 64 bit architecture and if my JRE was 32 or 64 bit from a JAVA program.


Soon I realised that "os.arch"  system property will only give you the architecture of the JRE, not of the underlying OS. It means, if you install a 32 bit JRE on a 64 bit system, System.getProperty("os.arch") will return  x86.

So I had to find another way to get the OS architecture. I came up with a simple JAVA program that uses the command line string "wmic OS get OSArchitecture" to get the underlying OS Architecture.

The following program will retrieve all the required parameters:

No comments:

Post a Comment