Skip to content

Environment setup (MacOS X 10.7)

AmailP edited this page Jul 31, 2011 · 12 revisions

Install JDK 7

Following the instructions on the MacOS X OpenJDK Wiki it's easily possible to compile the JDK 7 on MacOS X 10.7. Otherwise precompiled binary packages are hosted on Google Code: openjdk-osx-build.

The tools needed for the JDK compilation are the following:

  • Xcode 3.2.6 or later
  • Mercurial (hg)
  • JDK 1.6

I'm reporting below the required commands for the reader's convenience.

Get the code

> hg clone http://hg.openjdk.java.net/macosx-port/macosx-port
> cd macosx-port
> chmod 755 get_source.sh
> ./get_source.sh

Build

> make ALLOW_DOWNLOADS=true SA_APPLE_BOOT_JAVA=true ALWAYS_PASS_TEST_GAMMA=true ALT_BOOTDIR=`/usr/libexec/java_home -v 1.6` HOTSPOT_BUILD_JOBS=`sysctl -n hw.ncpu`

Smoke Test

> build/macosx-universal/j2sdk-bundle/1.7.0.jdk/Contents/Home/bin/java -version

Install

This step allows to install the newly created JDK in the user's Library folder.

> mkdir -p ~/Library/Java/JavaVirtualMachines
> cp -R build/macosx-universal/j2sdk-bundle/1.7.0.jdk ~/Library/Java/JavaVirtualMachines

Run

> export JAVA_HOME=`/usr/libexec/java_home --version 1.7`
> $JAVA_HOME/bin/java -version

Compile the Project Lambda langtools

The tools needed for the langtools are the following:

  • Mercurial (hg)
  • JDK 1.7
  • ant 1.7.1+

Get the code

> hg clone http://hg.openjdk.java.net/lambda/lambda/langtools
> cd langtools

Compile the langtools

> ant -Dboot.java.home=$JAVA_HOME -f make/build.xml

If everything went right, a javac executable will be available in the dist/bootstrap/bin. This is the java compiler that implements all the features introduced by the OpenJDK Project Lambda.

Compile and run Hello Closures World!

First of all we want to be able to easily call the new javac compiler. To do this we make a backup of the old executable and we replace it with a link to the new one.

> mv $JAVA_HOME/bin/javac $JAVA_HOME/bin/java_bkp
> ln -s `echo $PWD`/dist/bootstrap/bin/javac $JAVA_HOME/bin/javac
> ln -s `echo $PWD`/dist/bootstrap/lib/javac.jar $JAVA_HOME/lib/javac.jar

Now we create a new HelloClosuresWorld.java file and writing the following simple class

public class HelloClosuresWorld {
    public static void main(String[] args) {
        String whichWorld = "closures";
        new Thread( #{System.out.println("Hello " + whichWorld + " world!")} ).start();
    }
}

we compile the class

> $JAVA_HOME/bin/javac HelloClosuresWorld.class

and finally we execute it

> $JAVA_HOME/bin/java HelloClosuresWorld
Hello closures world!