Skip to content

Building and Packaging OpenJDK7 for OSX

dan zen edited this page Jan 3, 2017 · 34 revisions

Some pre-requisites are required to build OpenJDK7 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

obuildfactory expects to find a compiler named llvm-gcc, but later versions of XCode use the LLVM compiler by default, and removed that separate binary, so run:

sudo ln -s gcc /Applications/Xcode.app/Contents/Developer/usr/bin/llvm-gcc

git, mercurial (hg), and Apache Ant (ant)

You could find them on Brew or MacPorts sites.

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

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

Resetting the path

The build system is designed to work with the tools available on OS X. Particularly if you have other sources for common build tools, like e.g. Fink, it is suggested that you change your path to not use those versions.

export PATH="/usr/bin:/bin:/usr/sbin:/sbin:$PATH"

Building OpenJDK

Building is activated by XBUILD env var set to true.

cd ~/openjdkathome
COMPILER_WARNINGS_FATAL=false JAVAC_WARNINGS_FATAL=false XBUILD=true ./obuildfactory/openjdk7/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.7.0-u10-b09"
OpenJDK Runtime Environment (build 1.7.0-u10-b09-20121025)
OpenJDK 64-Bit Server VM (build 23.6-b03, mixed mode)
openjdk version "1.7.0-u10-b09"
OpenJDK Runtime Environment (build 1.7.0-u10-b09-20121025)
OpenJDK 64-Bit Server VM (build 23.6-b03, mixed mode)

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

ls -l OBF_DROP_DIR/openjdk7
total 367752
-rw-r--r--  1 henri  staff  30740364 25 oct 21:45 j2re-bundle-x86_64-u10-b09-20121025.tar.bz2
-rw-r--r--  1 henri  staff  30734607 25 oct 21:44 j2re-image-x86_64-u10-b09-20121025.tar.bz2
-rw-r--r--  1 henri  staff  63399134 25 oct 21:45 j2sdk-bundle-x86_64-u10-b09-20121025.tar.bz2
-rw-r--r--  1 henri  staff  63407811 25 oct 21:44 j2sdk-image-x86_64-u10-b09-20121025.tar.bz2

Images tarballs

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

mbp-rico:openjdkathome henri$ tar xvfj OBF_DROP_DIR/openjdk7/j2sdk-image-x86_64-u10-b09-20121025.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.7.0-u10-b09"
OpenJDK Runtime Environment (build 1.7.0-u10-b09-20121025)
OpenJDK 64-Bit Server VM (build 23.6-b03, 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/openjdk7/j2sdk-bundle-x86_64-u10-b09-20121025.tar.bz2
x jdk1.7.0.jdk/
x jdk1.7.0.jdk/Contents/
x jdk1.7.0.jdk/Contents/Home/
x jdk1.7.0.jdk/Contents/Info.plist
x jdk1.7.0.jdk/Contents/MacOS/
...
x jdk1.7.0.jdk/Contents/Home/bin/schemagen
x jdk1.7.0.jdk/Contents/Home/bin/serialver
x jdk1.7.0.jdk/Contents/Home/bin/servertool
x jdk1.7.0.jdk/Contents/Home/bin/tnameserv
x jdk1.7.0.jdk/Contents/Home/bin/unpack200
x jdk1.7.0.jdk/Contents/Home/bin/wsgen
x jdk1.7.0.jdk/Contents/Home/bin/wsimport
x jdk1.7.0.jdk/Contents/Home/bin/xjc

Set JAVA_HOME to test it :

mbp-rico:openjdkathome henri$ export JAVA_HOME=`pwd`/jdk1.7.0.jdk/Contents/Home
mbp-rico:openjdkathome henri$ java -version
openjdk version "1.7.0-u10-b09"
OpenJDK Runtime Environment (build 1.7.0-u10-b09-20121025)
OpenJDK 64-Bit Server VM (build 23.6-b03, mixed mode)

Packaging OpenJDK

Packaging is activated by XPACKAGE env var set to true

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

DMG files are located under OBF_DROP_DIR/openjdk7 OpenJDK7 will be installed under /Library/Java/JavaVirtualMachines/1.7.0u.jdk

To test newly installed OpenJDK, set JAVA_HOME

export JAVA_HOME=/Library/Java/JavaVirtualMachines/1.7.0u.jdk/Contents/Home
mbp-rico:openjdkathome henri$ java -version
openjdk version "1.7.0-u10-b09"
OpenJDK Runtime Environment (build 1.7.0-u10-b09-20121025)
OpenJDK 64-Bit Server VM (build 23.6-b03, 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/openjdk7/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.7-fastdebug-x86_64-jdk-u10-b09-20121026.dmg
-rw-r--r--@ 1 henri  staff    260314 26 oct 18:09 OpenJDK-OSX-1.7-fastdebug-x86_64-jre-u10-b09-20121026.dmg
-rw-r--r--  1 henri  staff  30743316 26 oct 18:08 j2re-bundle-fastdebug-x86_64-u10-b09-20121026.tar.bz2
-rw-r--r--  1 henri  staff        46 26 oct 18:07 j2re-image-fastdebug-x86_64-u10-b09-20121026.tar.bz2
-rw-r--r--  1 henri  staff  63394792 26 oct 18:08 j2sdk-bundle-fastdebug-x86_64-u10-b09-20121026.tar.bz2
-rw-r--r--  1 henri  staff        46 26 oct 18:07 j2sdk-image-fastdebug-x86_64-u10-b09-20121026.tar.bz2

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

/Library/Java/JavaVirtualMachines/1.7.0u.jdk/
/Library/Java/JavaVirtualMachines/1.7.0u.jre/
/Library/Java/JavaVirtualMachines/1.7.0u-fastdebug.jdk/
/Library/Java/JavaVirtualMachines/1.7.0u-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/openjdk7/macosx/standalone-job.sh