Skip to content

Building and Packaging OpenJDK8 for OSX

Henri Gomez edited this page Dec 20, 2018 · 12 revisions

Some pre-requisites are required to build OpenJDK8 on OSX.

XCode

Install XCode 4.5.x on Mountain Lion or XCode 4.4 on Lion with Command Line Tools installed

xcode should be activated via xcode-select

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

If you installed Command Line Tools, xcode-select should be

sudo xcode-select -switch /Library/Developer/CommandLineTools

git and mercurial (hg)

You could find them on Brew or MacPorts sites.

Ruby

Ruby 1.9 have issues in build so you should be sure Ruby 1.8 is used. If you're using rbenv, you could use :

rbenv local system

X11

X11 is required for building so it should installed on Lion.

Mountain Lion didn't provide it anymore but hopefully XQuartz could be used. Note, XQuartz forgot to install X11 include in correct location so fix it with symlink

sudo ln -s /usr/X11/include/X11 /usr/include/X11

Java 7

Java 7 should be installed, you could use Oracle Java7 or OpenJDK7 built from OBuildfactory :-)

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/openjdk8/macosx/standalone-job.sh

After some minutes you should see this logs :

#-- Build times ----------
Target all_product_build
Start 2012-10-25 22:10:11
End   2012-10-25 22:15:42
00:00:15 corba
00:00:06 hotspot
00:00:04 jaxp
00:00:07 jaxws
00:04:52 jdk
00:00:06 langtools
00:05:31 TOTAL
-------------------------
openjdk version "1.8.0-b62"
OpenJDK Runtime Environment (build 1.8.0-b62-20121028)
OpenJDK 64-Bit Server VM (build 25.0-b06, mixed mode)
openjdk version "1.8.0-b62"
OpenJDK Runtime Environment (build 1.8.0-b62-20121028)
OpenJDK 64-Bit Server VM (build 25.0-b06, mixed mode)

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

ls -l OBF_DROP_DIR/openjdk8
total 388056
-rw-r--r--  1 henri  staff  33413695 28 oct 19:01 j2re-bundle-x86_64-b62-20121028.tar.bz2
-rw-r--r--  1 henri  staff  33418087 28 oct 19:01 j2re-image-x86_64-b62-20121028.tar.bz2
-rw-r--r--  1 henri  staff  65930593 28 oct 19:01 j2sdk-bundle-x86_64-b62-20121028.tar.bz2
-rw-r--r--  1 henri  staff  65915985 28 oct 19:00 j2sdk-image-x86_64-b62-20121028.tar.bz2

Images tarballs

Images tarballs could be used like any others Unix Java, ie :

mbp-rico:openjdkathome henri$ tar xvfj OBF_DROP_DIR/openjdk8/j2sdk-image-x86_64-b62-20121028.tar.bz2
x j2sdk-image/
x j2sdk-image/ASSEMBLY_EXCEPTION
x j2sdk-image/bin/
x j2sdk-image/demo/
x j2sdk-image/include/
x j2sdk-image/jre/
x j2sdk-image/lib/
x j2sdk-image/LICENSE
x j2sdk-image/man/
...
x j2sdk-image/bin/tnameserv
x j2sdk-image/bin/unpack200
x j2sdk-image/bin/wsgen
x j2sdk-image/bin/wsimport
x j2sdk-image/bin/xjc

mbp-rico:openjdkathome henri$ ./j2sdk-image/bin/java -version
openjdk version "1.8.0-b62"
OpenJDK Runtime Environment (build 1.8.0-b62-20121028)
OpenJDK 64-Bit Server VM (build 25.0-b06, mixed mode)

Bundle tarballs

Bundle tarballs are designed for OSX integration and should be installed under /Library/Java/JavaVirtualMachines

mbp-rico:openjdkathome henri$ tar xvfj OBF_DROP_DIR/openjdk8/j2sdk-bundle-x86_64-b62-20121028.tar.bz2
x jdk1.8.0.jdk/
x jdk1.8.0.jdk/Contents/
x jdk1.8.0.jdk/Contents/Home/
x jdk1.8.0.jdk/Contents/Info.plist
x jdk1.8.0.jdk/Contents/MacOS/
...
x jdk1.8.0.jdk/Contents/Home/bin/schemagen
x jdk1.8.0.jdk/Contents/Home/bin/serialver
x jdk1.8.0.jdk/Contents/Home/bin/servertool
x jdk1.8.0.jdk/Contents/Home/bin/tnameserv
x jdk1.8.0.jdk/Contents/Home/bin/unpack200
x jdk1.8.0.jdk/Contents/Home/bin/wsgen
x jdk1.8.0.jdk/Contents/Home/bin/wsimport
x jdk1.8.0.jdk/Contents/Home/bin/xjc

Set JAVA_HOME to test it :

mbp-rico:openjdkathome henri$ export JAVA_HOME=`pwd`/jdk1.8.0.jdk/Contents/Home
mbp-rico:openjdkathome henri$ java -version
openjdk version "1.8.0-b62"
OpenJDK Runtime Environment (build 1.8.0-b62-20121028)
OpenJDK 64-Bit Server VM (build 25.0-b06, mixed mode)

Packaging OpenJDK

Packaging is activated by XPACKAGE env var set to true

cd ~/openjdkathome
XBUILD=true XPACKAGE=true ./obuildfactory/openjdk8/macosx/standalone-job.sh

DMG files are located under OBF_DROP_DIR/openjdk8 OpenJDK8 will be installed under /Library/Java/JavaVirtualMachines/1.8.0.jdk

To test newly installed OpenJDK, set JAVA_HOME

export JAVA_HOME=/Library/Java/JavaVirtualMachines/1.8.0.jdk/Contents/Home
mbp-rico:openjdkathome henri$ java -version
openjdk version "1.8.0-b62"
OpenJDK Runtime Environment (build 1.8.0-b62-20121028)
OpenJDK 64-Bit Server VM (build 25.0-b06, mixed mode)

Debug mode

OpenJDK could be built with debug mode, called fast-debug.

In this mode JVM will provide much more informations via flags like -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly

To active debug mode, set XDEBUG to true ie :

cd ~/openjdkathome
XDEBUG=true XBUILD=true XPACKAGE=true ./obuildfactory/openjdk8/macosx/standalone-job.sh

Debug Tarballs, DMGs and bundle dir will contains fastdebug :

-rw-r--r--@ 1 henri  staff  73115450 26 oct 18:09 OpenJDK-OSX-1.8-fastdebug-x86_64-jdk-b62-20121028.dmg
-rw-r--r--@ 1 henri  staff    260314 26 oct 18:09 OpenJDK-OSX-1.8-fastdebug-x86_64-jre-b62-20121028.dmg
-rw-r--r--  1 henri  staff  30743316 26 oct 18:08 j2re-bundle-fastdebug-x86_64-b62-20121028.bz2
-rw-r--r--  1 henri  staff        46 26 oct 18:07 j2re-image-fastdebug-x86_64-b62-20121028.tar.bz2
-rw-r--r--  1 henri  staff  63394792 26 oct 18:08 j2sdk-bundle-fastdebug-x86_64-b62-20121028.tar.bz2
-rw-r--r--  1 henri  staff        46 26 oct 18:07 j2sdk-image-fastdebug-x86_64-b62-20121028.tar.bz2

Debug packages install names also include fastdebug, allowing to install release and debug packages at same time :

/Library/Java/JavaVirtualMachines/1.8.0.jdk/
/Library/Java/JavaVirtualMachines/1.8.0.jre/
/Library/Java/JavaVirtualMachines/1.8.0-fastdebug.jdk/
/Library/Java/JavaVirtualMachines/1.8.0-fastdebug.jre/

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 XBUILD=true XPACKAGE=true ./obuildfactory/openjdk8/macosx/standalone-job.sh