Because on Apple with M1, M2 ... (Apple Silicon) it is possible to install both JDK for arm (aka arm64) or for Intel CPU (aka amd64), and it will just work, there is problem to tell (to colleague on other mac) how to check
How to check that installed JDK on mac is for arm64 or amd64 ?
System.getProperty("os.arch")
)For example mvn -v
used to be enough to tell all details.
mvn -v
Apache Maven 3.9.1 (2e178502fcdbffc201671fb2537d0cb4b4cc58f8)
Maven home: /opt/homebrew/Cellar/maven/3.9.1/libexec
Java version: 17.0.6, vendor: Amazon.com Inc., runtime: /Users/user/Library/Java/JavaVirtualMachines/corretto-17.0.6-1/Contents/Home
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "13.4", arch: "aarch64", family: "mac"
JDK java/javac don't give clue either.
javac -version
javac 17.0.6
java -version
openjdk version "17.0.6" 2023-01-17 LTS
OpenJDK Runtime Environment Corretto-17.0.6.10.1 (build 17.0.6+10-LTS)
OpenJDK 64-Bit Server VM Corretto-17.0.6.10.1 (build 17.0.6+10-LTS, mixed mode, sharing)
We also have JDK installed by scripts, JDK installed in docker container. There should be some common way to check.
If you only need to check by hand you can use the file
utility which, for executables, should tell you what architecture the binary was built for.
So assuming you want to know about the javac
that's on your path you can run
file $(which javac)
Or, more generally
file /path/to/your/binary
And read its output.
An example:
$ file $JAVA_HOME/bin/javac
/Users/user/Library/Java/JavaVirtualMachines/corretto-1.8.0_362/Contents/Home/bin/javac: Mach-O 64-bit executable x86_64
$ file $JAVA_OTHER_HOME/bin/javac
/Users/user/Library/Java/JavaVirtualMachines/corretto-1.8.0_362-1/Contents/Home/bin/javac: Mach-O 64-bit executable arm64