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.

12 Comments How to build OpenJDK 7 on Ubuntu 11.10 and 12.04

  1. cordoval

    one more thing is that you are mixing the title jdk7 and within the instructions you still rely on jdk6, so i am confused by that, could you please clarify? thanks!

    Reply
  2. cordoval

    ~ hg import ../fontfix.patch
    applying ../fontfix.patch
    unable to find ‘make/sun/font/Makefile’ for patching
    1 out of 1 hunks FAILED — saving rejects to file make/sun/font/Makefile.rej
    unable to find ‘src/share/native/sun/font/freetypeScaler.c’ for patching
    7 out of 7 hunks FAILED — saving rejects to file src/share/native/sun/font/freetypeScaler.c.rej
    abort: patch failed to apply

    Reply
  3. cordoval

    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.

    I am not sure where my jdk 1.6 is, I lately also have installed jdk 1.7 which i installed via the ubuntu software center utility.

    will try to modify the paths but already think it could fail to work.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.