Monday, August 27, 2012

How to build OpenJDK 7 on Ubuntu 11.10 and 12.04

This article will guide you to build OpenJDK in your 64-bit Ubuntu Linux (11.10 Oneiric Ocelot or 12.04 Precise Pangolin) without many trials and errors. It is based on the official OpenJDK build README, but the README file is out-of-date, and that’s why I wrote this guide.


  • You run 64-bit Ubuntu.
  • Your Sun/Oracle JDK 6 is installed at $HOME/.local/opt/jdk/1.6.
    • You can use your preferred installation location but you will have to adjust the scripts appear in this article.
  • You installed Apache Ant and the ant command is in your PATH variable.
  • You keep your development stuff at $HOME/Workspace.
    • This guide keeps OpenJDK source code at ~/Workspace/openjdk and HgForest at ~/Workspace/hgforest. However, you can keep them in different locations and adjust the scripts appear in this article.

Install required packages

apt-get install mercurial gawk g++ libcups2-dev libasound2-dev libfreetype6-dev libx11-dev libxt-dev libxext-dev libxrender-dev libxtst-dev libfontconfig1-dev

Install HgForest

hg clone "$HOME/Workspace/hgforest"
Edit your $HOME/.hgrc to add these lines:

Clone the OpenJDK 7 repository

hg fclone "$HOME/Workspace/openjdk"

Apply some patches

If you need to apply some patches, do it now, and then continue to build.

Build the OpenJDK 7

cd "$HOME/Workspace/openjdk"
export LANG=C
export ALT_BOOTDIR="$HOME/.local/opt/jdk/1.6"
export EXTRA_LIBS=/usr/lib/x86_64-linux-gnu/
source jdk/make/
make sanity && make && echo 'Images at: build/linux-amd64/j2sdk-image'
I usually write a build script that automatically sets the environment variables and calls make.
Once the build process is successful, you will find your OpenJDK image at build/linux-amd64/j2sdk-image.