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.

Assumptions

  • 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 https://bitbucket.org/pmezard/hgforest-crew/overview/ "$HOME/Workspace/hgforest"

Edit your $HOME/.hgrc to add these lines:

[extensions]
forest=~/Workspace/hgforest/forest.py

Clone the OpenJDK 7 repository

hg fclone http://hg.openjdk.java.net/jdk7u/jdk7u "$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"
unset JAVA_HOME
export LANG=C
export ALT_BOOTDIR="$HOME/.local/opt/jdk/1.6"
export ALLOW_DOWNLOADS=true
export EXTRA_LIBS=/usr/lib/x86_64-linux-gnu/libasound.so
source jdk/make/jdk_generic_profile.sh
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.