Skip to content

Building and Packaging OpenJDK7 for OSX

hgomez edited this page Oct 28, 2012 · 34 revisions

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

git and mercurial (hg)

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

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
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)

Potential issues

FreeType

FreeType 2.3+ is required by libfontmanager.dylib and referenced by dylib found during build.

mbp-rico:obuildfactory henri$ otool -L /Library/Java/JavaVirtualMachines/1.7.0u.jdk/Contents/Home/jre/lib/libfontmanager.dylib 
/Library/Java/JavaVirtualMachines/1.7.0u.jdk/Contents/Home/jre/lib/libfontmanager.dylib:
@rpath/libfontmanager.dylib (compatibility version 1.0.0, current version 1.0.0)
/opt/X11/lib/libfreetype.6.dylib (compatibility version 15.0.0, current version 15.1.0)
@rpath/libawt.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 56.0.0)
@rpath/libjava.dylib (compatibility version 1.0.0, current version 1.0.0)
@rpath/libjvm.dylib (compatibility version 1.0.0, current version 1.0.0)

If your destination machine didn't have X11 installed and matching X11 used at build time, fontmanager won't works.

Until OpenJDK dev team update build process to embed FreeType, be sure same X11 will be installed on destination machines. Patches have been provided in mid October 2012, wait and see.

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/