Building OpenJDK on Windows

Tomorrow I’ll be enjoying an OpenJDK hack session with Martijn Verburg (aka The Diabolical Developer). To prepare for this session he told us to follow the AdoptOpenJDK build instructions.

Most cool developers today seem to be using OS/X, but some of us are stuck on Windows laptops. I actually choose to stick with Windows 7 because every single client I’ve worked for has Windows workstations and only require the application to run on Windows. But anyway Martijn said: “Getting OpenJDK to build on Linux/Mac would be easy, Windows can be dicey”

With a bit of Googling and some small problems I’ve got it working just fine on my Windows 7 (64 bit). Most information I got was from this write-up, but I encountered some problems and could skip some steps I didn’t need.

All the tools mentioned are free, but you will have to install some Microsoft Visual C++ packages to compile (which most Java programmers try to avoid).

Windows SDK for Windows 7.1

Instead of the blogpost above mentioning this step second, I recommend doing it first. If you install VisualC++ 2010 Express first this step might fail with some weird error. The solution? Uninstall VisualC++ 2010 Express and first install Windows SDK for Windows 7.1.

So go here and install: http://www.microsoft.com/download/en/details.aspx?id=8279

Microsoft VisualC++ 2010 Express

Next install VisualC++ 2010 Express (beware, Microsoft tries to install another version, pick 2010 Express):
http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express
And next Windows Imaging Component (64-bit):
http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=1385

Cygwin (64 bit)

For some reason I ran into problems early on using the 64 bit Cygwin, so I decided to install the 64 bit version as well. This worked, so I recommend doing this.
During the installation you’ll need to add some development packages:

  • binutils
  • cpio
  • diffutils
  • file
  • gawk
  • gcc-core
  • m4
  • unzip
  • zip

I might have forgotten one or two, this will probably popup during the ‘configure’ step below. If you find a missing package, please tell me and I’ll update the post.

make

The version of ‘make’ that is packaged with Cygwin doesn’t work with OpenJDK. Instead we need to download the source from http://ftp.gnu.org/gnu/make/. I picked version 3.82 (this one is mentioned on the OpenJDK page). I downloaded and unzipped the source code here: C:\Projects\OpenJDK\make-3-82

To compile, fire up Cygwin and type:

$ cd /cygdrive/c/Projects/OpenJDK/make-3.82
$ ./configure
$ make

Now you could take the generated ‘make.exe’ and place it into the Cygwin bin directory, but this isn’t needed.

freetype

Next we need to have Freetype, this step is done exacly like descriped here. Only do the ‘Freetype’ chapter generating the lib and dll.

Once you’ve generated the lib+dll, make a new directory (I used C:\Projects\OpenJDK\freetype). Add the ‘include’ directory from the freetype source code used in the step before. Also create a ‘lib’ directory and place the generated lib and dll in it.

Hg/Ant/JDK7

The other article mentions you’ll need to install TortoiseHg, Apache Ant and a current JDK 7 (as bootstrap). I didn’t have to do this because I already had all three installed. But please go ahead, they are probably needed:

Getting OpenJDK sources

The other article mentions a lot of PATH requirements that need to be set. I didn’t encounter this at all because I configured my build in another way. First we’ll need to get the OpenJDK source code.

$ cd /cygdrive/C/Projects/OpenJDK/
$ mkdir jdk8_tl
$ hg clone http://hg.openjdk.java.net/jdk8/tl jdk8_tl
$ cd jdk8_tl
$ ./get_source.sh

This will create a new directory: /cygdrive/C/Projects/OpenJDK/jdk8_tl with all the sources!

Configure

Now we need to configure a build for OpenJDK. Instead of just calling ‘./configure’ we’ll need to add a few extra options, we’ll need to point it to the correct MAKE directory and we need to include our custom build freetype.

./configure MAKE=/cygdrive/C/Projects/OpenJDK/make-3.82/make.exe with_freetype=/cygdrive/C/Projects/OpenJDK/freetype

This will throw a lot of warnings, but in the end it should print something like this:

* OpenJDK target: OS: windows, CPU architecture: x86, address length: 64

Tools summary:
* Environment:    cygwin version 1.7.25(0.270/5/3) (root at /cygdrive/c/Development/cygwin64)
* Boot JDK:       java version "1.7.0_40"  Java(TM) SE Runtime Environment (build 1.7.0_40-b43)  Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)  (at /cygdrive/c/progra~1/java/jdk17~1.0_4)
* C Compiler:     Microsoft CL.EXE version 16.00.30319.01 (at /cygdrive/c/progra~2/micros~1.0/vc/bin/amd64/cl)
* C++ Compiler:   Microsoft CL.EXE version 16.00.30319.01 (at /cygdrive/c/progra~2/micros~1.0/vc/bin/amd64/cl)

Build performance summary:
* Cores to use:   7
* Memory limit:   16373 MB
* ccache status:  not available for your system

After the configure step you should have a new build directory added.
Mine was located at: /cygdrive/C/Projects/OpenJDK/jdk8_tl/build/windows-x86_64-normal-server-release

Build it

The next thing I did was to build everything, this can take anywhere from 10 to 40 minutes, my build took 20 minutes.

$ cd /cygdrive/C/Projects/OpenJDK/jdk8_tl
$ /cygdrive/C/Projects/OpenJDK/make-3.82/make.exe clean images

After a long wait and a lot of warnings and messages it says it created your very own JDK 8 build. Time to give it a try:

$ cd /cygdrive/C/Projects/OpenJDK/jdk8_tl
$ cd build/windows-x86_64-normal-server-release/images/j2sdk-image
$ bin/java -version

OpenJDK build completed

It worked!

Like I said before, I encountered some problems and errors along the way. Most involved the wrong Cygwin (32 bit), this caused bash to crash (STATUS_ACCESS_VIOLATION) during the configure phase. Also I ran into a problem installing ‘Microsoft SDK for Windows 7.1’ which required me to first uninstall Microsoft VisualC++ 2010. Another problem was not installing ‘diff’ in Cygwin (diffutils) so the build found some other diff.exe (from Git?) which gave differences during the actual build causing it to stop.

I might have forgotten to write down some step, if you encounter any problem (and solve them) please tell me so I can update this post!

Todo

One thing I should add is ‘ccache’. This tool greatly improves the build speed because it caches all unchanged classes/files. It was in Cygwin (32 bit) but it is missing in Cygwin (64 bit)… I’ll have to compile and install it myself. This is one thing I haven’t tried yet, but I probably should do!

Update: I’ve tried compiling and using ccache-3.1.9, but this broke the build. I might try different versions but for now I’ll just skip ‘clean’-ing altogether :-)