Categories: DevOps, Java

Windows OpenJDK Development Environment Setup

I documented how to set up an OpenJDK build environment for macOS and for Ubuntu Linux. Here is how to do the same for a Windows x86-64 environment on a Windows x86-64 machine. To create a JDK build for a Windows ARM64 environment, see the last section of this post.

  1. Install Visual Studio Code.
  2. Install Git and set Visual Studio Code as Git’s default editor.
  3. Install Visual Studio 2019. Ensure the Desktop Development with C++ workload is selected so that the C++ compiler is available.
The Visual Studio Desktop development with C++ workload
  1. Install a boot JDK. I used winget, the Windows package manager, to do this as outlined in the OpenJDK Windows installation instructions.
winget search Microsoft.OpenJDK
winget install Microsoft.OpenJDK.17
Microsoft Build of OpenJDK with Hotspot 17.0.1+12 (x64) 
Please watt while Windows configures Microsoft Build of OpenJDK with 
Hotspot 170 1+12(x64) 
Time remaining 7 seconds
  1. Install Cygwin using the command below.
setup-x86_64.exe -q -P autoconf -P make -P unzip -P zip
  1. Launch Cygwin, clone the OpenJDK repo then run bash configure. This should output an error if there are any missing dependencies. Once that completes successfully, make images will build the OpenJDK code.
mkdir ~/repos
cd ~/repos
git clone https://github.com/openjdk/jdk
cd ~/repos/jdk
bash configure
make images

To try out the local JDK build, run java.exe in the build folder, e.g.

cd ~/repos/jdk/build/windows-x86_64-server-slowdebug
cd jdk/bin
./java.exe -version

Troubleshooting

Keep in mind that make images can fail due to Cygwin-specific issues. The only workaround may be to downgrade Cygwin to a version known to work well, as I had to do when I ran into segfaults when running make.

Windows ARM64 JDK

To create a JDK build for a Windows ARM64 machine (as of this posting), you still need to set up the Windows x86-64 environment as described above with the additional changes below.

  1. Launch the Visual Studio Installer then install the “MSVC v142 – VS 2019 C++ ARM64 build tools (Latest)” item.
  2. Run bash configure with the additional –openjdk-target argument as outlined at https://github.com/microsoft/openjdk-aarch64
bash configure --openjdk-target=aarch64-unknown-cygwin

Running the ARM64 JDK on x86-64?

I was curious to see what happens if you try to run the ARM64 Java build in Cygwin on x86-64:

User@Machine /cygdrive/c/dev/repos/jdk/build/windows-aarch64-server-release/jdk/bin
$ ./java -version
-bash: ./java: cannot execute binary file: Exec format error

In the Windows command line we get this message in the terminal and the subsequent dialog box:

C:\dev\repos\jdk\build\windows-aarch64-server-release\jdk\bin>.\java.exe
This version of C:\dev\repos\jdk\build\windows-aarch64-server-release\jdk\bin\java.exe is not compatible with the version of Windows you're running. Check your computer's system information and then contact the software publisher.
Machine Type Mismatch

Launching it from Windows Explorer fails with this error:

Platform mismatch launching ARM64 Java on Windows x86-64

Article info




Leave a Reply

Your email address will not be published. Required fields are marked *