Happy PI Day

We had a little treat at the math department for Pi day:

I also have a treat for you. Here’s a little Java I threw together that maps the first thousand digits of Pi to keys on the piano. Warning: I don’t know why sound continues from the applet even after I navigate away, so be prepared to restart the browser to shut up the sound. That said, I think it sounds quite soothing, and of course since the sequence never repeats itself, you theoretically should never be dull of it 🙂

I had intended to post this a little earlier, but I was volunteering at a science and math conference for the whole day and haven’t had a moment to spare until now. Here is the source code; though the code that’s linked from the applet page is similar, (couldn’t upload it to Geocities due to scary file extension) that one is actually meant for Processing, which is what I used to export my code into an applet with a click of a button, not that I prefer clicking buttons though. I think the knowledge of creating an applet should be elementary, but I just wanted to pack what I had quickly before Pi day was over!

Anyways, hope you enjoyed your Pi day today. And for the parting fact: Albert Einstein’s birthday is today as well. Isn’t today such a nerdy day?

Building OpenJDK under Ubuntu

Shame: There was a typo in the command to clone jdk7 from the repo. The command below is now correct. Apologies for the confusion 😦

Manually building a large project really gives me an appreciation for how well the portage system in Gentoo automates the build process. To think that the process of pulling in dependencies, getting the source, applying patches, configuring, building, and merging binaries into a live system is executed by contributed ebuild scripts is very amazing, especially when you see it all before your very eyes. Unfortunately, searching for dependencies and setting up your build environment can be hectic, and the less patient miss out on an awesome experience.

This guide is dedicated to building OpenJDK entirely from the command line under Ubuntu 8.04. Assume all commands are executed in the directory where we will do all our work. Also, don’t forget to replace the instances of atsui (my username) with your own 😛

Install and configure Mercurial

First we’ll set up Mercurial, a distributed source control tool.

sudo apt-get install mercurial

We also want to set up Forest, an Mercurial extension that will let us recursively pull the entire OpenJDK from the repository. This command uses Mercurial to grab the extension and put it under the forest folder, which contains a python script we want called forest.py.

hg clone http://bitbucket.org/pmezard/hgforest-crew forest

Paste the following into .hgrc under your home directory to set up Forest.

username = atsui

You can check it works by typing in a command provided by Forest, eg.

hg fclone

Clone a copy of OpenJDK

Now let’s grab the JDK! This command puts everything in jdk7:

hg fclone http://hg.openjdk.java.net/jdk7/jdk7 jdk7

Fetch the binary plugs

OpenJDK still depends on some closed source blobs, which can be acquired and unpacked as follows:

wget http://www.java.net/download/openjdk/jdk7/promoted/b48/jdk-7-ea-plug-b48-linux-i586-19_feb_2009.jar

# accept the license agreement and install to cwd
java -jar jdk-7-ea-plug-b48-linux-i586-19_feb_2009.jar

Judging from the filename, perhaps this is frequently updated. Check out the downloads for the latest file.

Install library dependencies

Building from source often happens against various other libraries. Here is some of what I found was needed:

sudo apt-get install build-essential gawk libasound2-dev libfreetype6-dev libcups2-dev libxt-dev libx11-dev libxtst-dev

Configure the build environment

These commands will configure the build environment, but you should manually check your environment variables and unset anything related to java! A mysterious problem I ran into on my Gentoo box had to do with the fact that although I had unset JAVA_HOME and CLASSPATH, which the makefile checks for, I still had JAVAC and JDK_HOME set, which caused some mysterious hidden package errors. Find them and unset them before you build. The last command will check to see if the environment is reasonably prepared.

export ALT_BOOTDIR=/usr/lib/jvm/java-6-sun
export ALT_BINARY_PLUGS_PATH=/path/to/openjdk-binary-plugs
export LANG="C"
cd jdk7
make sanity

Build OpenJDK

This will start the build, which may halt on missing dependency errors.


Watch 24

Go and enjoy an episode of 24. Actually, the build takes a little longer than the time of one episode, so maybe you can make some popcorn while you’re at it.

With any luck, you will see this when you come back:

Control linux i586 1.7.0-internal build_product_image build finished:
Control linux i586 1.7.0-internal all_product_build build finished:
Control linux i586 1.7.0-internal all build finished:

You can then run

build/linux-i586/bin/java -version

to test your freshly baked OpenJDK, which should give something like

openjdk version "1.7.0-internal"
OpenJDK Runtime Environment (build 1.7.0-internal-atsui_2009_02_20_21_40-b00)
OpenJDK Client VM (build 15.0-b01, mixed mode)

Hopefully, that was pretty painless. Enjoy 🙂

searching for answers

Forum FAQs like to remind us to search previous posts and check with Google before posting: chances are that the answers are already out there. It’s true, but it takes some will to dig and some idea of what to find.

I am trying to build Violet UML editor from source, and building with maven seems pretty straightforward, pointing out missing dependencies as well as generating the command to splice it into the build once I fetch it myself. I had a heck of a time tracking down this one JNLP package for Java, which exposes some additional API in javax.jnlp.*. It was so confusing because everywhere I looked – the Gentoo packages, the Java Ranch forums – all pointed to Sun’s website for download. The only download available was the Java SE, which I had but obviously didn’t have what I was looking for since I have the build error, right? After much digging, I finally found the JNLP developer pack, which after Java 5 is included under the *samples* in the JDK. That could have been much easier.

In other news, I took a shot at using my Freerunner as a PDF reader today. I installed epdfview, a lightweight PDF viewer, but it was barely readable because I was in portrait mode. I assumed that the program would come out in landscape mode, but when I tried it and it didn’t, I assumed it was due to the Gestures program that detects the orientation and automatically rotates the screen to match. Digging deeper, I find that there’s actually a command to change the orientation of the screen!

xrandr -o [0-3]

0 is the default orientation (right side up) and it goes clockwise from there.

epdfview in landscape

The result is more lateral real estate and nicer reading experience. The big fat toolbar is open because I need the page scroll buttons since epdfview doesn’t have continuous page scrolling. I may just try evince later to try and really optimize the screen space, but it’s already as wide as it can get, which is okay.

In the end, it boils down to (1) whether you care enough to bother looking and (2) whether you know what you are looking for in the first place. Sometimes it just takes a while…