Building OpenJDK 7 on Ubuntu Linux 12.04 LTS

This recipe is similar to recipe Building OpenJDK 6 on Ubuntu Linux 12.04 LTS from Chapter 2, Building OpenJDK 6.

The build process of OpenJDK relies heavily on Unix-like development tools. Linux-based operating systems usually have top notch support for such tools, so building OpenJDK on Linux (and on Mac OS X) can be simpler than on Windows. For major distributions such as Fedora or Ubuntu, the build toolchain and all the dependencies are already included in distributions as packages and can be installed easily.

Ubuntu 12.04 LTS was chosen for this book because it is one of the most popular Linux distributions. For readers running other operating systems, Ubuntu 12.04 virtual images may be found online for the most popular virtualization tools, such as Oracle VirtualBox or VMware.

To build binaries for i586 and amd64 architectures, corresponding versions of Ubuntu should be used. The build instructions are exactly the same for both architectures so they won't be mentioned further in this recipe.

Getting ready

For this recipe, we will need clean Ubuntu 12.04 (server or desktop version) running.

How to do it...

The following instructions will help us to build OpenJDK 7:

  1. Install the prepackaged binaries of OpenJDK 6:
    sudo apt-get install openjdk-6-jdk
    
  2. Install the GCC toolchain and build dependencies:
    sudo apt-get build-dep openjdk-6
    
  3. Download and decompress the official OpenJDK 7 update 40 archive (results will be placed into the openjdk directory):
    wget http://download.java.net/openjdk/jdk7u40/promoted/b43/openjdk-7u40-fcs-src-b43-26_aug_2013.zip
    unzip -q openjdk-7u40-fcs-src-b43-26_aug_2013.zip
    
  4. Create a new text file buildenv.sh with the following environment settings:
    export LD_LIBRARY_PATH=
    export CLASSPATH=
    export JAVA_HOME=
    export LANG=C
    export ALT_BOOTDIR=/usr/lib/jvm/java-6-openjdk
  5. Import the environment into the current shell session (note a dot and a space before it):
    . buildenv.sh
  6. Start the build process from the openjdk directory:
    make 2>&1 | tee make.log
  7. Wait for the build to finish, and try to run the newly built binaries:
    cd build/linux-amd64/j2sdk-image/
    ./bin/java –version
    openjdk version "1.7.0-internal"
    OpenJDK Runtime Environment (build 1.7.0-internal-ubuntu_2014_02_08_08_56-b00)
    OpenJDK 64-Bit Server VM (build 24.0-b56, mixed mode)
    

How it works...

The prepackaged binaries of OpenJDK 6 are required because some of the build steps are run using the external Java runtime.

The build-dep command is used to install all the dependencies that are required to build the specified package. As Ubuntu packaged OpenJDK 6 is quite close to the official OpenJDK 6, this command will install almost all the required dependencies.

After a successful build on the amd64 platform, JDK files will be placed into build/linux-amd64/j2sdk-image and JRE files will be placed into build/linux-amd64/j2re-image. On the i586 platform, the build/linux-i586 path will be used instead. An additional package of Server JRE that contains JDK without demos and samples will be placed into the j2sdk-server-image directory.

There's more...

The Javadoc generation takes a lot of time and is the most memory consuming step of the build. It may be skipped with an additional environment variable:

export NO_DOCS=true

Contrary to previous version, OpenJDK 7 supports parallel (multicore) native library compilation. The following environment variables may be used for the jdk and hotspot modules respectively:

PARALLEL_COMPILE_JOBS=N
HOTSPOT_BUILD_JOBS=N

This build has generated a milestone tag and build number b00. Predefined build numbers and milestones may be set using additional environment variables:

export MILESTONE=ubuntu-build
export BUILD_NUMBER=b30

The cacerts file may be provided during the build, using additional environment variable:

export ALT_CACERTS_FILE=path/to/cacerts

For amd64 builds preinstalled Java provided by variable ALT_BOOTDIR may be either the amd64 or i586 build. The i586 binaries consume less memory and may be used for amd64 builds on limited hardware.

OpenJDK 7 has the same minimum build requirements on Linux as the previous version, so Debian 5.0 Lenny may be used to build the most compatible version.

See also