Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect MacOS arm64 and x86/x64 in Java

I dont have access to a mac and I need to detect if the MacOS currently running is ARM64 or x64/x86 in java programmatically. Its going to be used to download chromedriver from chrome-for-testing.

Currently, I'm using this code to download:

String osName = System.getProperty("os.name", "").toLowerCase();
if(osName.contains("darwin") || osName.contains("mac")) {
    // FIXME: no check for ARM64 arch
    _zipName = chromeForTesting ? "chromedriver-mac-x64.zip" : "chromedriver_mac64.zip";
}
like image 494
bramar2 Avatar asked Feb 03 '26 15:02

bramar2


1 Answers

something along the following (edited and tested on macpro)

cat GetSystemProperty.java 
public class GetSystemProperty {

    public static void main(String[] args) {
        String osName = System.getProperty("os.name");
        String osArch = System.getProperty("os.arch");

        System.out.println("OS name: " + osName);
        System.out.println("OS architecture: " + osArch);
    }
}

java GetSystemProperty
OS name: Mac OS X
OS architecture: x86_64

MacBook-Pro-15: glennstevenson$ 
uname -a
MacBook-Pro-15: 20.6.0 Darwin Kernel Version 20.6.0: Thu Jul  6 22:12:47 PDT 2023; root:xnu-7195.141.49.702.12~1/RELEASE_X86_64 x86_64

NB: a case-insensitive test may be wisest!

As always, test before use !

like image 163
ticktalk Avatar answered Feb 06 '26 06:02

ticktalk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!