How can I check the bitness of my OS using Java? (J2SE, not os.arch)
System.getProperty("os.arch");
Should be available on all platforms, see the Java System Properties Tutorial for more information.
But 64 bit Windows platforms will lie to the JVM if it is a 32 bit JVM. Actually 64 bit Windows will lie to any 32 bit process about the environment to help old 32 bit programs work properly on a 64 bit OS. Read the MSDN article about WOW64 for more information.
As a result of WOW64, a 32 bit JVM calling System.getProperty("os.arch")
will return "x86". If you want to get the real architecture of the underlying OS on Windows, use the following logic:
String arch = System.getenv("PROCESSOR_ARCHITECTURE");
String wow64Arch = System.getenv("PROCESSOR_ARCHITEW6432");
String realArch = arch != null && arch.endsWith("64")
|| wow64Arch != null && wow64Arch.endsWith("64")
? "64" : "32";
See also:
HOWTO: Detect Process Bitness
Why %processor_architecture% always returns x86 instead of AMD64
Detect whether current Windows version is 32 bit or 64 bit
How to determine 32-bit OS or 64-bit OS from Java application
You can run
System.getProperty("os.arch")
to retrieve the systems architecture. My Windows 64bit system will return amd64
as os.arch
value.
How to distinguish 32 bit from 64 bit java version in jnlp files
This is explained in the documentation, here: http://docs.oracle.com/javase/7/docs/technotes/guides/javaws/developersguide/syntax.html#resources
It doesn't say which arch
values make sense, though. You would want it to work for different JVM implementations and versions. I googled around for a while and here's what I've ended up using:
<resources>
<java version="1.6+"/>
<jar href="lwjgl-2.8.4.jar"/>
<jar href="lwjgl_util-2.8.4.jar"/>
</resources>
<!-- LWJGL Linux 64-bit native libraries -->
<resources os="Linux" arch="amd64">
<nativelib href="lwjgl-amd64-linux.jar"/>
</resources>
<resources os="Linux" arch="x86_64">
<nativelib href="lwjgl-amd64-linux.jar"/>
</resources>
<!-- LWJGL Linux 32-bit native libraries -->
<resources os="Linux" arch="x86">
<nativelib href="lwjgl-x86-linux.jar"/>
</resources>
<resources os="Linux" arch="i386">
<nativelib href="lwjgl-x86-linux.jar"/>
</resources>
<!-- LWJGL Windows 64-bit native libraries -->
<resources os="Windows" arch="amd64">
<nativelib href="lwjgl-amd64-win.jar"/>
</resources>
<resources os="Windows" arch="x86_64">
<nativelib href="lwjgl-amd64-win.jar"/>
</resources>
<!-- LWJGL Windows 32-bit native libraries -->
<resources os="Windows" arch="x86">
<nativelib href="lwjgl-x86-win.jar"/>
</resources>
<resources os="Windows" arch="i386">
<nativelib href="lwjgl-x86-win.jar"/>
</resources>
<!-- LWJGL MAC OS/X native libraries -->
<resources os="Mac">
<nativelib href="lwjgl-macosx.jar"/>
</resources>
Detect whether current Windows version is 32 bit or 64 bit
See the batch script listed in How To Check If Computer Is Running A 32 Bit or 64 Bit Operating System. It also includes instructions for checking this from the Registry:
You can use the following registry location to check if computer is running 32 or 64 bit of Windows operating system:
HKLM\HARDWARE\DESCRIPTION\System\CentralProcessor\0
You will see the following registry entries in the right pane:
Identifier REG_SZ x86 Family 6 Model 14 Stepping 12
Platform ID REG_DWORD 0x00000020(32)
The above “x86” and “0x00000020(32)” indicate that the operating system version is 32 bit.
Related Topics
Change a Method at Runtime via a Hot Swap Mechanism
Which Artifacts Should I Use for Jaxb Ri in My Maven Project
What Are the Main Uses of Yield(), and How Does It Differ from Join() and Interrupt()
Using Java to Decrypt Openssl Aes-256-Cbc Using Provided Key and Iv
"Comparison Method Violates Its General Contract!" - Timsort and Gridlayout
Exception in Initializer Error in Java When Using Netbeans
How to Create a Project from Existing Source in Eclipse and Then Find It
Httpservletrequest - Setcharacterencoding Seems to Do Nothing
Mocking Files in Java - Mock Contents - Mockito
How to Stop a Scheduled Task That Was Started Using @Scheduled Annotation
How to Create a Custom Exception Type in Java
How to Stop Selenium from Creating Temporary Firefox Profiles Using Web Driver
How to Get a Spring Bean in a Servlet Filter
Does Java Support Inner/Local/Sub Methods
What Package Naming Convention Do You Use for Personal/Hobby Projects in Java
Java 8: Where Is Trifunction (And Kin) in Java.Util.Function? or What Is the Alternative