Install x86_64 JDK via sdkman on M1/M2/M3/M4 macOS

Sometimes we need to install an x86_64 JDK on the M1/M2/M3/M4 macOS for some reason, for example, I was testing Kafka Stream 2.7 application locally on a M3 MacBook Pro. Its Rocksdb library didn’t have the native lib for M series Macs, I had to install an x86_64 JDK on it to run the application

By default, the sdkman only lists the JDKs that match the hardware architecture. But we can edit the ~/.sdkman/var/platform by changing darwinarm64 to darwinx64 temporally. So the steps would be:

  1. Edit ~/.sdkman/var/platform and replace the darwinarm64 with darwinx64
  2. Run sdk flush to flush sdkman’s local state
  3. Run sdk list java and the non-installed listed JDKs which should be already X64 version
  4. Run sdk install java xxx as normal and sdk use java xxx, now the installed JDK should
  5. Run cat which java | file - we will see /dev/stdin: Mach-O 64-bit executable x86_64
  6. Don’t forget to change the darwinx64 back to darwinarm64 after finishing the testing of X64 JDK.

The exception when an ARM JDK is used.

java.lang.UnsatisfiedLinkError: /private/var/folders/h0/m23_22tn3cg71g72b_c4tmgr0000gn/T/librocksdbjni4698946407096025405.jnilib: dlopen(/private/var/folders/h0/m23_22tn3cg71g72b_c4tmgr0000gn/T/librocksdbjni4698946407096025405.jnilib, 0x0001): tried: '/private/var/folders/h0/m23_22tn3cg71g72b_c4tmgr0000gn/T/librocksdbjni4698946407096025405.jnilib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/private/var/folders/h0/m23_22tn3cg71g72b_c4tmgr0000gn/T/librocksdbjni4698946407096025405.jnilib' (no such file), '/private/var/folders/h0/m23_22tn3cg71g72b_c4tmgr0000gn/T/librocksdbjni4698946407096025405.jnilib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64'))

留下评论

您的邮箱地址不会被公开。 必填项已用 * 标注