How to build OpenJDK 7 on Ubuntu 11.10 and 12.04

2012-04-10 13:47

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.

---
NOTE: Google Translate is poor at translating Korean. Do NOT guess from its result.

·

Comment

12 Comments

I tried your steps, but every time my Linux box gets crashed.

Faisal · 2012-05-16 18:01 · # · Reply

My MBP 2011 just builds OpenJDK 7 fine. No crash.

Trustin Lee · 2012-06-08 12:58 · # · Reply

please are you on gtalk i am doing it now, please ping me

cordoval · 2012-06-08 13:18 · # · Reply

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.

cordoval · 2012-06-08 13:21 · # · Reply

You can just download it from java.oracle.com and run the .bin installer to extract the distribution, and put it somewhere you want it to be.

Trustin Lee · 2012-06-08 17:03 · # · Reply

~ 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

cordoval · 2012-06-08 13:52 · # · Reply

Just use a patch command. It seems like you are applying the patch on a wrong directory – ‘hg import’ fails to find the files to patch.

Trustin Lee · 2012-06-08 17:05 · # · Reply

I used the patch command, and it is the same error. Please help me :’( been two days already on this.

cordoval · 2012-06-09 16:29 · # · Reply

I guess I gave all the information I can give. (cd openjdk/jdk; patch -p1 < fontfix.patch) just works for me.

Trustin Lee · 2012-06-09 18:47 · # · Reply

now the patch command worked ok

now trying to compile …

thanks

cordoval · 2012-06-11 13:01 · # · Reply

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!

cordoval · 2012-06-11 14:25 · # · Reply

ok so we figured out how to do things properly. It was more messy than we expected, the build was successful however the results were like this:

!http://img6.imagebanana.com/img/8maciqss/Selection_309.png!

cordoval · 2012-06-12 00:00 · # · Reply

 
  • Preview 버튼 누르고 reCAPTCHA 입력 후 Submit 버튼까지 눌러야 실제로 게시됩니다.
  • Make sure to answer the reCAPTCHA and click the Submit button to get your comment posted. It's not enough to click the Preview button only! -- See why.

·

---