Thursday, September 30, 2010

OpenJDK and Project Lambda on MacOS X 10.6

Want to try out the upcoming JDK 7 on your Mac? And closures from Project Lambda, due in JDK 8? There are currently no official binary build available for MacOS X, but it turns out that it's actually gotten pretty easy to build these projects yourself. With just 10 minutes of work and a little waiting you could have a working build! Here's my account of how to do it.

First, install Mercurial and the forest extension. If you have Macports, this is as easy as

$ sudo port install mercurial
$ sudo port install hg-forest

Now check out the OpenJDK bsd-port tree:

$ hg fclone http://hg.openjdk.java.net/bsd-port/bsd-port

You have to download soylatte16-amd64-1.0.3.tar.bz2 from

http://landonf.bikemonkey.org/static/soylatte/#get

and unpack it. This is needed for bootstrapping the build.

Use this build script:

export SOYLATTE_HOME=$HOME/src/soylatte16-amd64-1.0.3
export JAVA_HOME=$SOYLATTE_HOME


cd bsd-port


time env -i PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin \
 make \
 CC=gcc-4.0 CXX=g++-4.0 \
 ALT_BOOTDIR=$SOYLATTE_HOME \
 JAVA_TOOLS_DIR=$SOYLATTE_HOME/bin \
 ALLOW_DOWNLOADS=true \
 ALT_FREETYPE_HEADERS_PATH=/usr/X11R6/include \
 ALT_FREETYPE_LIB_PATH=/usr/X11R6/lib \
 ANT_HOME=/usr/share/ant \
 NO_DOCS=true \
 HOTSPOT_BUILD_JOBS=1

This is based on Sam Pullara's Building OpenJDK 1.7.0 post. I just had to add ALLOW_DOWNLOADS=true to avoid this error:

ERROR: Cannot find source for project jaxp.

When you run the script (if all goes well) you should get a lot of output that ends with

Control bsd i586 1.7.0-internal all build finished: 10-09-30 15:37

On my MacBook Pro (Core i7, 4 GB RAM, SSD) this took a little over 20 minutes.

Now move your newly built JDK somewhere more sensible:

$ mv bsd-port/build/bsd-i586/j2sdk-image ~/jdk7

Test the install:

$ jdk7/bin/java -version
openjdk version "1.7.0-internal"
OpenJDK Runtime Environment (build 1.7.0-internal-kjetilod_2010_09_30_15_15-b00)
OpenJDK Server VM (build 19.0-b05, mixed mode)

Project Lambda
For bonus points, here's how you build Project Lambda (based on a post by Rémi Forax to the lambda-dev mailing list):

Checkout the source:

$ hg clone http://hg.openjdk.java.net/lambda/lambda/langtools

Build it with Ant (I just used 1.7.1 which comes with MacOS X):

$ cd lambda/langtools/
$ ant -Dboot.java.home=$HOME/jdk7 -f make/build.xml

From Rémi's post:

To run the compiler: 

/bin/java -cp classes.jar

com.sun.tools.javac.Main yoursource.java



and to run your code:

/bin/java -cp classes.jar:. YourClass

1 comment:

John Yeary said...

Please check out the official Build instructions, we are always looking for people to update them.

http://wikis.sun.com/display/OpenJDK/Darwin10Build