Skip to content

How to build and package OpenJDK 9 on Linux

Henri Gomez edited this page Dec 21, 2016 · 8 revisions

Some pre-requisites are required to build OpenJDK9 on Linux

Build and package pre-requisites

Be sure to have git, mercurial, gcc/g++, make and required libs and some mandatory tools installed. Java 7 should be installed.

Ensure JAVA_HOME env var point to a valid Java 8 location, example for openSUSE 13.1 :

export JAVA_HOME=/opt/obuildfactory/openjdk8
export PATH=$JAVA_HOME/bin:$PATH

You could also define Java 8 to be use with OBF_JAVA8_HOME env var, ie on Mint 17 :

export OBF_JAVA8_HOME=/usr/lib/jvm/java-8-openjdk-amd64

Ubuntu 16.04 / Mint 18.x

sudo apt-get install git mercurial zip bzip2 unzip tar curl
sudo apt-get install ccache make gcc g++ ca-certificates ca-certificates-java
sudo apt-get install libx11-dev libxext-dev libxrender-dev libxtst-dev libxt-dev
sudo apt-get install libasound2-dev libcups2-dev libfreetype6-dev
sudo apt-get install build-essential ruby ruby-dev
sudo apt-get install openjdk-8-jdk
sudo apt-get install pkg-config
sudo gem install fpm

Ubuntu 14.04 / Mint 17.x

sudo apt-get install git mercurial zip bzip2 unzip tar curl
sudo apt-get install ccache make gcc g++ ca-certificates ca-certificates-java
sudo apt-get install libX11-dev libxext-dev libxrender-dev libxtst-dev libxt-dev
sudo apt-get install libasound2-dev libcups2-dev libfreetype6-dev
sudo apt-get install build-essential ruby ruby-dev
sudo apt-get install openjdk-8-jdk
sudo apt-get install pkg-config
sudo gem install fpm

Ubuntu 12.x-13.x / Mint 14-16

sudo apt-get install git mercurial zip bzip2 unzip tar curl
sudo apt-get install ccache make gcc g++ ca-certificates ca-certificates-java
sudo apt-get install libX11-dev libxext-dev libxrender-dev libxtst-dev  
sudo apt-get install libasound2-dev libcups2-dev libfreetype6-dev
sudo apt-get install build-essential ruby-dev pkg-config
sudo apt-get install openjdk-8-jdk
sudo gem install fpm

openSUSE / SLES

sudo zypper install git-core mercurial zip bzip2 unzip tar 
sudo zypper install ccache make gcc gcc-c++ ca-certificates-cacert ca-certificates-mozilla
sudo zypper install libstdc++-devel alsa-devel cups-devel xorg-x11-devel libjpeg62-devel giflib-devel 
sudo zypper install curl rpm-build gpg
sudo zypper install java-1_8_0-openjdk-devel

CentOS 5/6

sudo yum install git-core mercurial zip bzip2 unzip tar which
sudo yum install ccache make gcc gcc-c++ libstdc++-devel 
sudo yum install alsa-lib-devel cups-devel libX11-devel libXext-devel libXt-devel libXrender-devel libXtst-devel libXi-devel libjpeg-devel giflib-devel freetype-devel
sudo yum install curl rpm-build gpg
sudo yum install java-1.8.0-openjdk-devel

Fedora 16/20

sudo yum install git-core mercurial zip bzip2 unzip tar 
sudo yum install ccache make gcc gcc-c++ 
sudo yum install libstdc++-devel libstdc++-static alsa-lib-devel cups-devel libX11-devel libXext-devel libXt-devel libXrender-devel libXtst-devel libXi-devel libjpeg-devel giflib-devel freetype-devel 
sudo yum install curl rpm-build gpg rpmbuild rpm-sign
sudo yum install java-1.8.0-openjdk-devel

Prepare environment

For example, you want to build OpenJDKs in openjdkathome directory under your home directory.

mkdir ~/openjdkathome
cd ~/openjdkathome
git clone https://github.com/hgomez/obuildfactory.git

Building OpenJDK

Building is activated by XBUILD env var set to true

cd ~/openjdkathome
XUSE_NEW_BUILD_SYSTEM=true XBUILD=true ./obuildfactory/openjdk9/linux/standalone-job.sh

After some minutes you should see this logs :

Creating jre jimage
Creating jdk jimage
Stopping sjavac server
Finished building target 'images' in configuration 'linux-x86_64-normal-server-release'
openjdk version "9-internal"
OpenJDK Runtime Environment (build 9-internal+0-adhoc.henri.openjdk9)
OpenJDK 64-Bit Server VM (build 9-internal+0-adhoc.henri.openjdk9, mixed mode)
openjdk version "9-internal"
OpenJDK Runtime Environment (build 9-internal+0-adhoc.henri.openjdk9)
OpenJDK 64-Bit Server VM (build 9-internal+0-adhoc.henri.openjdk9, mixed mode)
~/openjdkathome/sources/openjdk9/build/linux-x86_64-normal-server-release/images ~/openjdkathome

You'll find JDK/JRE tarballs under OBF_DROP_DIR/openjdk9

ls -l OBF_DROP_DIR/openjdk9
total 511556
-rw-r--r-- 1 henri henri 337646490 déc.  21 11:29 jdk-x86_64-b94-20161221.tar.bz2
-rw-r--r-- 1 henri henri 186172850 déc.  21 11:30 jre-x86_64-b94-20161221.tar.bz2

Clean vs Incremental build

By default, build are performed in incremental mode, ie only updated code is recompiled, reducing overall build time.

But experience in OpenJDK show that weird things happens sometimes and it's better to start from scratch and perform a clean build.

To activate clean mode, use XCLEAN env var ie :

cd ~/openjdkathome
XCLEAN=true XUSE_NEW_BUILD_SYSTEM=true XBUILD=true ./obuildfactory/openjdk9/linux/standalone-job.sh

Native Packages

We have 2 ways to build native packages, stock RPM with rpmbuild and DEB/RPM using FPM

To use stock RPM packaging, use XPACKAGE env var ie :

cd ~/openjdkathome
XPACKAGE=true XCLEAN=true XUSE_NEW_BUILD_SYSTEM=true XBUILD=true ./obuildfactory/openjdk9/linux/standalone-job.sh

To activate FPM and so DEB or RPM, also use XUSE_FPM :

cd ~/openjdkathome
XUSE_FPM=true XPACKAGE=true XCLEAN=true XUSE_NEW_BUILD_SYSTEM=true XBUILD=true ./obuildfactory/openjdk9/linux/standalone-job.sh

Sample on Mint 18 (DEB) :

j2sdk-image/jre/lib/cmm/GRAY.pf
j2sdk-image/jre/lib/applet/
j2sdk-image/jre/LICENSE
j2sdk-image/jre/THIRD_PARTY_README
Setting from flags: category=language {:level=>:info}
Setting from flags: description=OpenJDK 8 native package {:level=>:info}
Setting from flags: epoch= {:level=>:info}
Setting from flags: iteration= {:level=>:info}
Setting from flags: maintainer=Henri Gomez <henri.gomez@gmail.com> {:level=>:info}
Setting from flags: name=openjdk9 {:level=>:info}
Setting from flags: url=https://github.com/hgomez/obuildfactory/ {:level=>:info}
Setting from flags: version=1.9.0-b05 {:level=>:info}
Converting dir to deb {:level=>:info}
No deb_installed_size set, calculating now. {:level=>:info}
Reading template {:path=>"/var/lib/gems/1.9.1/gems/fpm-0.4.29/lib/fpm/../../templates/deb.erb", :level=>:info}
Creating {:path=>"/tmp/package-deb-build20130222-11224-1749g70/control.tar.gz", :from=>"/tmp/package-deb-build20130222-11224-1749g70/control", :level=>:info}
Created deb package {:path=>"openjdk9_1.8.0-b77_amd64.deb"}
~/openjdkathome/obuildfactory/openjdk9/linux/rpm ~/openjdka

You'll then find DEB or RPM files under OBF_DROP_DIR/openjdk9 next to tarballs :

ls -l OBF_DROP_DIR/openjdk9/
total 851528
-rw-r--r-- 1 henri henri 337643601 déc.  21 11:54 jdk-x86_64-b94-20161221.tar.bz2
-rw-r--r-- 1 henri henri 186172646 déc.  21 11:54 jre-x86_64-b94-20161221.tar.bz2
-rw-r--r-- 1 henri henri 348132144 déc.  21 11:55 openjdk9_1.9.0-b94_amd64.deb