Java 17, shipped 2021-09
There is an official sub-project on the OpenJDK project for porting to the Apple Silicon hardware, JEP 391: macOS/AArch64 Port.
That work is done, built for Java 17, delivered in September of 2021.
The Apple Silicon port benefits from work done on the Windows on ARM port. That work is done, delivered in Java 16. Previous to that, Linux on ARM support was added to Java 9.
👉 So Java 17 for macOS on Apple Silicon (AArch64, ARM) Macs is available now.
Update: Java 18 is now available too, as is early access Java 19.
You can choose from a variety of vendors to obtain an installer/binary. Off the top of my head, those may include Azul Systems, SAP, BellSoft, Amazon, Microsoft, Adoptium (formerly AdoptOpenJDK), Oracle, Red Hat/IBM, Pivotal, and perhaps more.
Regarding JavaFX, at least two of those vendors, Azul Systems and BellSoft, offer an edition of their JDK product that bundles the OpenJFX libraries. That may be of interest to you, as an alternative to adding the libraries to your app.
If you need further assistance with that Azul product, you can purchase support from that company. Or post a Question here with the detailed specifics of your JavaFX work and its point of failure on Apple Silicon. Ideally, provide a minimal example of code demonstrating the problem.
Earlier Java
Some of those vendors listed above have back-ported earlier versions of Java (Java 8, Java 11, maybe others) to macOS on Apple Silicon. That work is not an official part of the OpenJDK project support for Apple Silicon, only Java 17+ is.
Answer from Basil Bourque on Stack OverflowJava 17, shipped 2021-09
There is an official sub-project on the OpenJDK project for porting to the Apple Silicon hardware, JEP 391: macOS/AArch64 Port.
That work is done, built for Java 17, delivered in September of 2021.
The Apple Silicon port benefits from work done on the Windows on ARM port. That work is done, delivered in Java 16. Previous to that, Linux on ARM support was added to Java 9.
👉 So Java 17 for macOS on Apple Silicon (AArch64, ARM) Macs is available now.
Update: Java 18 is now available too, as is early access Java 19.
You can choose from a variety of vendors to obtain an installer/binary. Off the top of my head, those may include Azul Systems, SAP, BellSoft, Amazon, Microsoft, Adoptium (formerly AdoptOpenJDK), Oracle, Red Hat/IBM, Pivotal, and perhaps more.
Regarding JavaFX, at least two of those vendors, Azul Systems and BellSoft, offer an edition of their JDK product that bundles the OpenJFX libraries. That may be of interest to you, as an alternative to adding the libraries to your app.
If you need further assistance with that Azul product, you can purchase support from that company. Or post a Question here with the detailed specifics of your JavaFX work and its point of failure on Apple Silicon. Ideally, provide a minimal example of code demonstrating the problem.
Earlier Java
Some of those vendors listed above have back-ported earlier versions of Java (Java 8, Java 11, maybe others) to macOS on Apple Silicon. That work is not an official part of the OpenJDK project support for Apple Silicon, only Java 17+ is.
Adoptium recently (2022-Oct-22) released Java 11 that supports Apple Silicon:
https://adoptium.net/temurin/releases/?version=11
And for a summary of supported platforms:
https://adoptium.net/supported-platforms/
How about JVM/JDK on Apple Silicon ? good / bad for Java ?
macos - Java/JDK for the Apple Silicon chips - Stack Overflow
Provide native builds for ARM based Macs
java - How to compile OpenJDK 11 on an M1 Macbook? - Stack Overflow
Videos
A command line approach (thanks to the Homebrew team and the hard work of @vladimir-kempik and other openjdk contributors on the JEP-391 branch)
# Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install OpenJDK
brew install openjdk
Verify it's installed:
$(brew --prefix openjdk)/bin/java --version
Verify it's for the arm64 hardware:
file $(brew --prefix openjdk)/bin/java
# /opt/homebrew/opt/openjdk/bin/java: Mach-O 64-bit executable arm64
Note: To install openjdk system-wide, follow the on-screen instructions provided by Homebrew.
Yes.
On this page: AdoptOpenJDK Latest Releases you can select 'macOS' from the 'Operating System' dropdown, and then from 'Architecture', it's currently only x64, but soonish there should be AArch64 or ARM64 (those are usually the shortcodes for 64-bit ARM). Possibly, as Apple no doubt has a bunch of extensions built into their M1 designs, and Apple gets its own.
If you instead leave Operation System on 'any', you'll note aarch64 is in there, and this gets you to a Linux release for ARM processors. That (probably) won't run on macOS on M1 hardware, but that's 95% of the work already done.
So: It's not there yet, but note that JDKs for ARM have been available for more than decade, and whilst JDK 15 has dropped support for a bunch of exotic OS/architecture combinations (such as Solaris), ARM development has always remained at least partially relevant (even if so far it's mostly an Oracle commercial license offering). That is to say: It should not be a herculean effort to create an adoptopenjdk release that runs on M1s natively, so presumably, it will happen. But, it's an open source effort, so if you're anxious, by all means, read up and contribute :)
Apple has not given any details on this architecture whatsoever until November 10th 2020, unless you bought a development kit box for it (a Mac Mini with an A14 chip, which isn't an M1 chip, but close enough I guess), and signed a big NDA.
As a rule, open source projects will run as fast as possible in the opposite direction if you wave an NDA around, so if you dislike this state of affairs, I don't think it's wise to complain to adoptopenjdk or other packagers and open source projects about it :)
Fortunately, now it's out, and an NDA is no longer required. My assumption is that the ARM branch of the OpenJDK source code + the macOS bits that already exist for the macOS x64 release can be combined rather easily once someone with some familiarity with the OpenJDK source code has an M1-based macOS system to test it on, which should mean an adoptopenjdk macos-aarch64 release should be here within the month.
But, open source. You didn't pay them, you have no contract, and they don't owe it to you. Donate to the effort or contribute a pull request if you want it to go faster.
UPDATE:
- Azul's M1 OpenJDK builds
- Microsoft's (yes, really) GitHub source repo for an early access OpenJDK16 build for macOS on AArch64. Note that Microsoft's been working on the OpenJDK branch of AArch64 (for ARM-based Windows 10) for a while, which goes back to: A lot of the hard work was already done.
tl;dr
target (64) differs … number of bits … in the target (32)
Apple Silicon chips for macOS (M1, M2) are all 64-bit architectures. Do not compile for 32-bit.
I want to compile jdk in M1 MacBook.
Do not try to compile OpenJDK. Codebase is large and complicated. And no need, as others provide binaries & installers.
For a Mac using Apple Silicon rather than Intel x86-64, I suggest obtaining a distribution of Java 17 for macOS / AArch64, released 2021-09, from any of several vendors.
Or, use a build of earlier versions of Java ported to Apple Silicon by various vendors. For example, Azul Systems announced 2020-11 plans to ship builds of OpenJDK 8 and 11 for Apple Silicon, ARM-based Macs. I see downloads available now from that company for Java 11.0.13+8 on both Intel Macs and Apple Silicon Macs.
Details
Few of us ever compile the very large and complicated codebase of OpenJDK. Instead, we look to any of several vendors providing builds and installers. If your goal is to be productive in Java programming, then compiling the Java JDK toolset is not the best use of your time.
Java 17 was released 2021-09. OpenJDK officially supports macOS on Apple Silicon: JEP 391: macOS/AArch64 Port. You have your choice of builds/installers from any of several vendors such as SAP, Red Hat/IBM, BellSoft, Azul Systems, Oracle, Adoptium/AdoptOpenJDK, Microsoft, Amazon, Pivotal, and more. These builds/installers will be based largely or entirely on the OpenJDK codebase.
Vendors such as Azul Systems provide Apple Silicon builds for the current version 19 as well as the long-term support (LTS) versions 8, 11, and 17. Java 17 is the latest LTS version, to be supported for many years. So I would suggest Java 17 for deployment.
I myself have been using Java 17, 18, and 19, as well as early-access 20, on a couple of M1 MacBook Pro laptops with IntelliJ and Maven on Big Sur & Monterey. Working well, no problems.
Update: As of 2023-11, I would suggest the current version 21 for deployment, as it is the latest LTS version. Also, you can now obtain JDK binaries and installers from many vendors, including Amazon, Microsoft, Azul Systems, BellSoft, Oracle, Adoptium, SAP, IBM, Red Hat, Linux apt-get, FreeBSD Ports and Packages, and more. Most of these provide editions of their JDK products for both Intel Macs and Apple Silicon Macs.
Compiling Java
As commented, your specific error is likely due to you compiling for 32-bit ARM rather than 64-bit ARM architecture used by Apple for their M1 chip and M2 chip families.
If you are curious about, or have an academic interest in compiling Java from the OpenJDK codebase, I suggest examining the open-sourced tooling at Adoptium (formerly AdoptOpenJDK). The tooling for building early-access builds at the OpenJDK site may also be open-sourced but I don’t know for certain.
You can build OpenJDK 11.0.12 on an M1 MacBook, with the help of Homebrew, by running:
brew install --build-from-source --verbose openjdk@11
Xcode is a prerequisite, you can download it from there https://developer.apple.com/download/more/ (Apple ID needed).
You probably also have to run:
xcode-select --install
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
I've tested it and it builds perfectly.
Oracle has a poor record for making it easy to install and configure Java, but using Homebrew, the latest OpenJDK (Java 14) can be installed with:
brew install --cask adoptopenjdk8
For the many use cases depending on an older version (commonly Java 8), the AdoptOpenJDK project makes it possible with an extra step.
brew tap adoptopenjdk/openjdk
brew install --cask adoptopenjdk8
Existing users of Homebrew may encounter Error: Cask adoptopenjdk8 exists in multiple taps due to prior workarounds with different instructions. This can be solved by fully specifying the location with brew install --cask adoptopenjdk/openjdk/adoptopenjdk8.
Note: Oracle Java 8/9/10 is no longer available for public download (license change).
First install and update brew from Terminal:
bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew tap homebrew/cask-versions
brew update
NEW as of June 2019
To install the JDKs from AdoptOpenJDK:
brew tap adoptopenjdk/openjdk
brew install --cask adoptopenjdk8
brew install --cask adoptopenjdk9
brew install --cask adoptopenjdk10
brew install --cask adoptopenjdk11
OLD
Java 8:
brew install --cask java8
Java Latest:
brew install --cask java