Skip to content

Instantly share code, notes, and snippets.

@st235
Forked from NotAlexNoyle/openjdk-12-pi-3-guide.txt
Created September 8, 2019 20:23
Show Gist options
  • Save st235/e0ff75043a1e6ee14f16807de36dea6e to your computer and use it in GitHub Desktop.
Save st235/e0ff75043a1e6ee14f16807de36dea6e to your computer and use it in GitHub Desktop.
A step-by-step tutorial on installing OpenJDK 12 on a Raspberry Pi 3 running Raspbian
Do you use your Raspberry Pi 3 to develop Java applications using OpenJDK? You may have noticed that the latest version available on the default apt repositories is OpenJDK 9. This is because the armhf architecture is underserved by the Oracle open source community. Luckilly, you can build and run the latest version (OpenJDK 12.x) on your device. It will just take some time, given the minimal power of the Pi 3's CPU.
The first step is to boot into raspbian and launch the shell.
Next, we are going to create 1GB of swap space for the build.
Get the 'pv' package:
> sudo apt-get install pv
Create the swap space:
> sudo dd if=/dev/zero bs=1M count=1024 | pv | sudo dd of=/var/SWAPFILE
Add it to your system:
> sudo mkswap /var/SWAPFILE
Edit the following lines in /etc/dphys-swapfile with VIM or a similar plain text editor:
CONF_SWAPFILE=/var/SWAPFILE
CONF_SWAPSIZE=1024
Reboot to apply changes:
> sudo reboot
Next we need to install the latest available pre-built OpenJDK, in order to build the next major version. To get to OpenJDK 12 eventually, we first need to install the package that contains OpenJDK 9, then we will use that to build OpenJDK 10, which will be used to build 11, then 11 will be used to build 12, and so on from there. Upon future releases this process can theoretically be continued.
Install OpenJDK 9 from the official repos:
> sudo apt-get install openjdk-9-jdk
Install the remaining build dependencies:
> sudo apt-get install autoconf build-essential libx11-dev libxext-dev libxrender-dev libxtst-dev libxt-dev libcups2-dev libasound2-dev libfontconfig1-dev zip mercurial libxrandr-dev x11proto-randr-dev
Run the following to pull down the latest OpenJDK 10 source code:
> hg clone http://hg.openjdk.java.net/jdk-updates/jdk10u
Change directories into the cloned OpenJDK 10 Repository:
> cd jdk10u/
Make the configure file executable
> chmod +x configure
Configure the project to prepare for building:
> ./configure --disable-warnings-as-errors --with-native-debug-symbols=none --with-version-pre="armhf" --with-version-build=10
Build the project (this will take hours):
> make LOG=cmdlines images
Install the project:
> sudo make install
Test it:
> java -version
You should see something similar to this:
openjdk 10.0.1-armhf 2018-04-17
OpenJDK Runtime Environment (build 10.0.1-armhf+10)
OpenJDK Server VM (build 10.0.1-armhf+10, mixed mode)
Next, we will clean up.
> cd ..
> sudo rm -rf jdk10u/
Now pull down OpenJDK 11, which we will build with OpenJDK 10:
> hg clone http://hg.openjdk.java.net/jdk-updates/jdk11u/
Change directories into the cloned OpenJDK 11 Repository:
> cd jdk11u
Make the configure file executable
> chmod +x configure
Configure the project to prepare for building:
> ./configure --disable-warnings-as-errors --with-native-debug-symbols=none --with-version-pre="armhf" --with-version-build=11
Build the project (this will take hours):
> make LOG=cmdlines images
Install the project:
> sudo make install
Test it:
> java -version
You should see something like this:
openjdk version "11.0.3-armhf" 2019-04-16
OpenJDK Runtime Environment (build 11.0.3-armhf+11-adhoc.pi.jdk11u)
OpenJDK Server VM (build 11.0.3-armhf+11-adhoc.pi.jdk11u, mixed mode)
Next, we will clean up.
> cd ..
> sudo rm -rf jdk10u/
Now pull down OpenJDK 12, which we will build with OpenJDK 11:
> hg clone http://hg.openjdk.java.net/jdk-updates/jdk12u/
Change directories into the cloned OpenJDK 12 Repository:
> cd jdk12u
Make the configure file executable
> chmod +x configure
Configure the project to prepare for building:
> ./configure --disable-warnings-as-errors --with-native-debug-symbols=none --with-version-pre="armhf" --with-version-build=12
Build the project (this will take hours):
> make LOG=cmdlines images
Install the project:
> sudo make install
Test it:
> java -version
That's it! You now have a Raspberry Pi 3 with OpenJDK 12. Code away!
- NotAlexNoyle
Credit to Jim Connors from oracle for his tutorial [here](https://blogs.oracle.com/jtc/build-jdk-10-for-your-raspberry-pi-right-on-your-device) that was very helpful in coming up with this one!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment