Because you decided to learn a Java virtual machine, you're going to start by compiling your own JDK. This article is the first article to learn about Java virtual machines, and there will be more related articles later.
Get Source code
The source code version chosen for this article is 1.7. You can use the following command to obtain the source code:
1) Install the latest version of mercurial
Mercurial is a distributed version control system similar to Git, but is similar in use to subversion. If you've used subversion, it's easy to move to mercurial. The installation commands are as follows:
$ sudo apt-get install python$ sudo apt-get install python-all-dev$ sudo apt-get install python-setuptools$ sudo easy_inst All-u Mercurial
To detect whether the installation was successful:
$ HG--versionmercurial Distributed SCM (version 3.1.2) (see http://mercurial.selenic.com for more information) Copyright ( C) 2005-2014 Matt Mackall and othersthis are free software; See the source for copying conditions. There is nowarranty; Not even to merchantability or FITNESS for A particular PURPOSE.
2) Download the source code
$ cd ~$ HG clone http://hg.openjdk.java.net/jdk7u/jdk7u60 openjdk-7-src$ CD openjdk-7-src$ Sh./get_source.sh
This will allow the source code to be downloaded to the OPENJDK-7-SRC directory.
Please don't get the source code like this:
$ mkdir ~/jdk$ CD ~/jdk/$ wget Http://www.java.net/download/openjdk/jdk7/promoted/b147/openjdk-7-fcs-src-b147-27_jun _2011.zip$ Unzip Openjdk-7-fcs-src-b147-27_jun_2011.zip
This address gets the source code is not up to date, will have the following bug:
MAKE[5]: Entering directory '/home/ruifengshan/jdk/openjdk/build/linux-amd64-debug/hotspot/outputdir ' make-f/home/ Ruifengshan/jdk/openjdk/hotspot/make/linux/makefile checksmake[6]: Entering directory '/home/ruifengshan/jdk/ Openjdk/build/linux-amd64-debug/hotspot/outputdir ' >&2 echo ' * * * This OS was not supported: ' Uname-a '; Exit 1;*** This OS was not supported:linux ruifengshan-ubuntu 3.13.0-37-generic #64-ubuntu SMP Mon Sep 21:28:38 UTC 201 4 x86_64 x86_64 x86_64 gnu/linuxmake[6]: * * * [check_os_version] Error 1 ...
System
This article uses the Linux system, the release version is Ubuntu 14.04 64 bit.
Building a compilation environment
1) Install the required GCC and other software, you can use the following command to install at once
$ sudo apt-get libasound-dev libcups2-dev build-essential$ sudo apt-get install libxt-dev$ sudo apt-get install libxtst-de V
2) Install Ant
$ mkdir/export/ant$ cd/export/ant$ wget http://www.gtlib.gatech.edu/pub/apache//ant/binaries/ apache-ant-1.9.4-bin.tar.gz$ sudo tar-zxf apache-ant-1.9.4-bin.tar.gz$ sudo vim/etc/profile
Enter the following content:
Export Ant_home=/export/ant/apache-ant-1.9.4export path= $PATH: $ANT _home/bin
When you are finished, use the following command to make the settings effective:
$ source/etc/profile
3) Install the Java environment
Compiling also requires a runtime package for the JDK, which is needed to compile the part of the JDK that is written in Java code. about how to install Java here will not repeat. The directory where Java is installed in this article is:/export/java6/jdk1.6.0_45.
4) environment variable setting
At the command line, enter the following:
Export alt_bootdir=/export/java6/jdk1.6.0_45 export lang=c export allow_downloads=true unset classpathunset Java_home
5) Install FreeType
Execute the following command to install FreeType
$ mkdir ~/freetype$ cd ~/freetype$ wget http://ftp.yzu.edu.tw/nongnu//freetype/freetype-2.5.3.tar.gz$ tar-zxf freetype-2.5.3.tar.gz$ CD freetype-2.5.3$./configure$ make$ sudo make install
After successful installation, you will also need to enter the following command:
$ sudo ln-s/usr/local/include/freetype2/freetype/usr/local/include/freetype
Otherwise, the following error will occur:
Error:freetype version 2.3.0 or higher is required ....
6) Perform make sanity check
Run make sanity check in the OpenJDK directory. If you output the following at the end, the proof settings are correct.
$ cd ~/openjdk-7-src$ make sanity ... Sanity check passed.
Start compiling
Execute the following command:
$ cd ~/openjdk-7-src$ make Allow_downloads=true
If the following occurs, the table name is compiled successfully:
############################################################################# Leaving JDK for Target (s) sanity all Docs images ################################################################################## Build time 00:07:50 JDK for Target (s) Sanity all docs images #################################################################### ##########--Build times----------Target all_product_buildstart 2014-10-29 13:35:25end 2014-10-29 13:43:4800:00:16 corba00:00:07 hotspot00:00:02 jaxp00:00:05 jaxws00:07:50 jdk00:00:03 langtools00:08:23 Total-------------------------make[1]: Leaving directory '/HOME/RUIFENGSHAN/JDK/OPENJDK-7-SRC '
Test
Test the results of the following compilation using the following command:
$ cd ~/jdk/openjdk-7-src$ build/linux-amd64/bin/java-versionopenjdk version "1.7.0-internal" OpenJDK Runtime Environment (build 1.7.0-internal-ruifengshan_2014_10_29_12_50-b00) OpenJDK 64-bit Server VM (build 24.60-b09, mixed Mode
Note the (build 1.7.0-internal-ruifengshan_2014_10_29_12_50-b00), which contains your own name.
Reprint Please specify Source:http://blog.csdn.net/iAm333
Build the JDK yourself under Linux