This article recorded in Ubuntu14.04 (64bit) under the whole process of compiling OpenJDK7, during the period of several pits, recorded here, hope to help by the relevant requirements of students.

Why compile OpenJDK

One of the best ways to get a peek inside the JDK is to build your own JDK and debug JDK source code to understand how the JDK works. The most appropriate choice in the open source JDK is the OpenJDK.

Compile environment

Ubuntu 14.04 x86_64
Copy the code

Download the OpenJDK source code and JDK

Download the official packaged Source directly from OpenJDK 7 Updates Project Source Releases here. Openjdk 7u6-fcS-src-b24-28 openJDK 7U6-FCS-src-b24-28 OpenJDK 7U6-FCS-src-b24-28 openJDK 7U6-FCS-src-b24-28 We also need a JDK to compile the source code, here I use Oracle JDK6, you can download from the official website, or from here: Oracle JDK6. Next, let’s install the required dependencies.

Install dependencies

sudo apt-get install build-essential gawk m4 libasound2-dev 
libcups2-dev libxrender-dev xorg-dev xutils-dev x11proto-print-dev 
binutils libmotif3 libmotif-dev ant
Copy the code

Writing compilation scripts

With that done, let’s write a shell script to compile the source code as follows:

#! / bin/bash export LANG = C export ALT_BOOTDIR = / home/absfree/jdk6 has/jdk1.6.0 _45 # allows automatic download depend on the package of export ALLOW_DOWNLOADS = true # use precompiled header files Export USE_PRECOMPILED_HEADER=true # Export BUILD_LANGTOOLS=true export BUILD_JAXP=true export BUILD_JAXWS=true export BUILD_CORBA=true export BUILD_HOSTPOT=true export BUILD_JDK=true # Build version export SKIP_DEBUG_BUILD=false export SKIP_FASTDEBUG_BUILD=true export DEBUG_NAME=debug # Avoid building javaws and browser Java plug-ins BUILD_DEPLOY = false # don't build the installation package BUILD_INSTALL = false # set deposit compile results directory export ALT_OUTPUTDIR = / home/absfree/its/build the unset CLASSPATH unset JAVA_HOME make sanity make 2>&1 | tee $ALT_OUTPUTDIR/build.logCopy the code

We need to set ALT_BOOTDIR to the directory where we just installed Oracle JDK6 and ALT_OUTPUTDIR to the directory where we want to store the compilation results. We create a build.sh file, put the above content in it, and put the build.sh file in the directory where we put the OpenJDK source code.

Begin to compile

Before starting the compilation, we also need to modify the source directory in a file, the file is/JDK/SRC/share/classes/Java/util/CurrencyData properties. What we need to do is to change the following time in the document to a time within 10 years:

AZ=AZM; The 2005-12-31-20-00-00; AZN MZ=MZM; The 2006-06-30-22-00-00; MZN RO=ROL; The 2005-06-30-21-00-00; RON TR=TRL; The 2004-12-31-22-00-00; TRY VE=VEB; The 2008-01-01-04-00-00; VEFCopy the code

With the above changes, we can start compiling with the following command:

cd 
sh build.sh
Copy the code

Not surprisingly, after a patient wait, it will compile successfully. We get the following build directory:

Among them, the J2SDK-Image directory stores the complete compilation results of the entire JDK. Go to the entire directory and type “java-version”. The result is as follows:

That’s it:)

The resources

In-depth Understanding of The Java Virtual Machine (Version 2) (Douban)